Skip to content

Instantly share code, notes, and snippets.

@diefferson
Last active August 6, 2019 19:50
Show Gist options
  • Save diefferson/d745ec0ce13a5565de2882b99405e2cd to your computer and use it in GitHub Desktop.
Save diefferson/d745ec0ce13a5565de2882b99405e2cd to your computer and use it in GitHub Desktop.
Função Para substituir caracteres com acentos por caracteres comuns
<?php
function removerAcentos( $string ) {
$mapaAcentosHex = array(
'a'=> '/[\xE0-\xE6]/',
'A'=> '/[\xE0-\xE6]/',
'e'=> '/[\xE8-\xEB]/',
'E'=> '/[\xE8-\xEB]/',
'i'=> '/[\xEC-\xEF]/',
'I'=> '/[\xEC-\xEF]/',
'o'=> '/[\xF2-\xF6]/',
'O'=> '/[\xF2-\xF6]/',
'u'=> '/[\xF9-\xFC]/',
'U'=> '/[\xF9-\xFC]/',
'c'=> '/\xE7/',
'C'=> '/\xE7/',
'n'=> '/\xF1/',
'N'=> '/\xF1/'
);
foreach ($mapaAcentosHex as $letra => $expressaoRegular) {
$string = preg_replace( $expressaoRegular, $letra, $string);
}
return $string;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment