Skip to content

Instantly share code, notes, and snippets.

@deyvin
Created September 26, 2011 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deyvin/1243154 to your computer and use it in GitHub Desktop.
Save deyvin/1243154 to your computer and use it in GitHub Desktop.
removendo Acentos com php
<?
function removeAcentos($str) {
$enc = (mb_detect_encoding($str, 'UTF-8', true)) ? 'UTF-8' : 'ISO-8859-1';
$acentos = array('A' => '/&Agrave;|&Aacute;|&Acirc;|&Atilde;|&Auml;|&Aring;/',
'a' => '/&agrave;|&aacute;|&acirc;|&atilde;|&auml;|&aring;/',
'C' => '/&Ccedil;/',
'c' => '/&ccedil;/',
'E' => '/&Egrave;|&Eacute;|&Ecirc;|&Euml;/',
'e' => '/&egrave;|&eacute;|&ecirc;|&euml;/',
'I' => '/&Igrave;|&Iacute;|&Icirc;|&Iuml;/',
'i' => '/&igrave;|&iacute;|&icirc;|&iuml;/',
'N' => '/&Ntilde;/',
'n' => '/&ntilde;/',
'O' => '/&Ograve;|&Oacute;|&Ocirc;|&Otilde;|&Ouml;/',
'o' => '/&ograve;|&oacute;|&ocirc;|&otilde;|&ouml;/',
'U' => '/&Ugrave;|&Uacute;|&Ucirc;|&Uuml;/',
'u' => '/&ugrave;|&uacute;|&ucirc;|&uuml;/',
'Y' => '/&Yacute;/',
'y' => '/&yacute;|&yuml;/',
'a.' => '/&ordf;/',
'o.' => '/&ordm;/');
return strtoupper(preg_replace($acentos, array_keys($acentos), htmlentities($str, ENT_NOQUOTES, $enc)));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment