function slugify($text) {
// trim
$text = trim($text);
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '_', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// remove duplicate -
$text = preg_replace('~-+~', '_', $text);
// lowercase
$text = strtolower($text);
return $text;
}
// trim
$text = trim($text);
// replace non letter or digits by -
$text = preg_replace('~[^\pL\d]+~u', '_', $text);
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
// remove duplicate -
$text = preg_replace('~-+~', '_', $text);
// lowercase
$text = strtolower($text);
return $text;
}
No comments:
Post a Comment