Created
November 5, 2019 10:19
-
-
Save irkreja/c59188e7316c028ac439a90aa0fb6522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Helpers; | |
class Helper { | |
public static function bn_slug($string = null, $separator = "-") { | |
if (is_null($string)) { | |
return ""; | |
} | |
// Remove spaces from the beginning and from the end of the string | |
$string = trim($string); | |
// Lower case everything | |
// using mb_strtolower() function is important for non-Latin UTF-8 string | more info: http://goo.gl/QL2tzK | |
$string = mb_strtolower($string, "UTF-8");; | |
// Make alphanumeric (removes all other characters) | |
// this makes the string safe especially when used as a part of a URL | |
// this keeps latin characters and bengali charactrs as well | |
$string = preg_replace("/[^a-z0-9_\s-অআইঈউঊঋৠঌৡএঐওঔকখগঘঙচছজঝঞটঠডঢণতথদধনপফবভমযরলশষসহড়ঢ়য়ৰৱঁংঃ়ািীুূৃৄেৈোৌ্ৗ০১২৩৪৫৬৭৮৯৲৳৴৵৶৷৸৹৺]/u", "", $string); | |
// Remove multiple dashes or whitespaces | |
$string = preg_replace("/[\s-]+/", " ", $string); | |
// Convert whitespaces and underscore to the given separator | |
$string = preg_replace("/[\s_]/", $separator, $string); | |
return $string; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment