-
-
Save jpalala/4a67601f83c9c571d26c to your computer and use it in GitHub Desktop.
Slug URL generator for seo (removes spaces hyphens, and other characters)
This file contains hidden or 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 | |
function slugify($str) { | |
$search = array('Ș', 'Ț', 'ş', 'ţ', 'Ş', 'Ţ', 'ș', 'ț', 'î', 'â', 'ă', 'Î', 'Â', 'Ă', 'ë', 'Ë'); | |
$replace = array('s', 't', 's', 't', 's', 't', 's', 't', 'i', 'a', 'a', 'i', 'a', 'a', 'e', 'E'); | |
$str = str_ireplace($search, $replace, strtolower(trim($str))); | |
$str = preg_replace('/[^\w\d\-\ ]/', '', $str); | |
$str = str_replace(' ', '-', $str); | |
return preg_replace('/\-{2,}', '-', $str); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
return preg_replace('/-{2,}', '-', $str);
should be
return preg_replace('/-{2,}/', '-', $str);
with the added slash at the end of the regex