Created
October 28, 2015 15:33
-
-
Save radicaldingos/8133be390374d620cc93 to your computer and use it in GitHub Desktop.
Function to strip accents of a string
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 | |
/** | |
* Fonction permettant de se débarrasser des accents dans une chaîne de caractères, | |
* en les remplaçant par la lettre correspondante | |
* | |
* @param string $string Chaîne à nettoyer | |
* | |
* @return string Chaîne débarrassée d'accents | |
*/ | |
function stripAccents($string){ | |
return str_replace( | |
array('à','á','â','ã','ä','å','ç','è','é','ê','ë','ì', | |
'í','î','ï','ñ','ò','ó','ô','õ','ö','ø','ù','ú', | |
'û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Ç','È','É', | |
'Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö', | |
'Ù','Ú','Û','Ü','Ý'), | |
array('a','a','a','a','a','a','c','e','e','e','e','i', | |
'i','i','i','n','o','o','o','o','o','o','u','u', | |
'u','u','y','y','A','A','A','A','A','C','E','E', | |
'E','E','I','I','I','I','N','O','O','O','O','O', | |
'U','U','U','U','Y'), | |
$string | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cette solution est à privilégier par rapport à l'équivalent utilisant la fonction strtr - en tout cas avec PHP 5.6 ou antérieure - qui fonctionne bien tant qu'on utilise pas de chaîne encodée en UTF-8.
This solution is preferred over the equivalent using the ** strtr ** function - at least with PHP 5.6 or earlier - which works well as long as you do not use a UTF-8 encoded string.