Skip to content

Instantly share code, notes, and snippets.

@smalot
Created November 18, 2013 14:54
Show Gist options
  • Save smalot/7529083 to your computer and use it in GitHub Desktop.
Save smalot/7529083 to your computer and use it in GitHub Desktop.
PHP function which removes accent
/**
* Found on http://www.weirdog.com/blog/php/supprimer-les-accents-des-caracteres-accentues.html
*/
function wd_remove_accents($str, $charset='utf-8') {
$str = htmlentities($str, ENT_NOQUOTES, $charset);
$str = preg_replace('#&([A-za-z])(?:acute|cedil|circ|grave|orn|ring|slash|th|tilde|uml);#', '\1', $str);
$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); // pour les ligatures e.g. 'œ'
$str = preg_replace('#&[^;]+;#', '', $str); // supprime les autres caractères
return $str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment