Created
September 24, 2013 21:02
-
-
Save diogoca/6691191 to your computer and use it in GitHub Desktop.
Php Slug Function
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
public function slug($name) | |
{ | |
$name = mb_strtolower($name, 'UTF-8'); | |
$pattern = array( | |
'/[âãàáä]/u', | |
'/[êèéë]/u', | |
'/[îíìï]/u', | |
'/[ôõòóö]/u', | |
'/[ûúùü]/u', | |
'/[ç]/u', | |
'/^[^a-z0-9]+/u', | |
'/[^a-z0-9]+$/u', | |
'/[^a-z0-9]+/u', | |
); | |
$replacement = array( | |
'a', | |
'e', | |
'i', | |
'o', | |
'u', | |
'c', | |
'', | |
'', | |
'-' | |
); | |
return preg_replace($pattern, $replacement, $name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment