Created
May 5, 2012 13:44
-
-
Save eoghanobrien/2602550 to your computer and use it in GitHub Desktop.
Modifies a string to remove all non ASCII characters and spaces.
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
| /** | |
| * Modifies a string to remove all non ASCII characters and spaces. | |
| * Note : Works with UTF-8 | |
| * | |
| * @param string $string The text to slugify | |
| * @return string The slugified text | |
| */ | |
| function toSlug ($string) { | |
| $string = utf8_decode($string); | |
| $string = html_entity_decode($string); | |
| $a = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ'; | |
| $b = 'AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn'; | |
| $string = strtr($string, utf8_decode($a), $b); | |
| $ponctu = array("?", ".", "!", ","); | |
| $string = str_replace($ponctu, "", $string); | |
| $string = trim($string); | |
| $string = preg_replace('/([^a-z0-9]+)/i', '-', $string); | |
| $string = strtolower($string); | |
| $string = trim($string, '-'); | |
| return utf8_encode($string); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment