note 85431 deleted from function.str-replace by philip
| From: | philip@php.net | Date: | Wed, 07 Oct 2009 07:59:58 +0000 |
| Subject: | note 85431 deleted from function.str-replace by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-161450@lists.php.net to get a copy of this message | ||
Note Submitter: marco dot carvalho at onda dot com dot br
----
If you need to replace áóÃóú and other special char, you need encondig type suport.
For this, just use htmlentities and some regular expressions
<?PHP
function RemoveAcentos($str, $enc = "UTF-8"){
$acentos = array(
'A' =>
'/À|Á|Â|Ã|Ä|Å/',
'a' =>
'/à|á|â|ã|ä|å/',
'C' => '/Ç/',
'c' => '/ç/',
'E' => '/È|É|Ê|Ë/',
'e' => '/è|é|ê|ë/',
'I' => '/Ì|Í|Î|Ï/',
'i' => '/ì|í|î|ï/',
'N' => '/Ñ/',
'n' => '/ñ/',
'O' => '/Ò|Ó|Ô|Õ|Ö/',
'o' => '/ò|ó|ô|õ|ö/',
'U' => '/Ù|Ú|Û|Ü/',
'u' => '/ù|ú|û|ü/',
'Y' => '/Ý/',
'y' => '/ý|ÿ/',
'a.' => '/ª/',
'o.' => '/º/'
);
return preg_replace($acentos, array_keys($acentos), htmlentities($str,ENT_NOQUOTES, $enc));
}
?>