note 50081 deleted from function.str-replace by bjori
| From: | bjori@php.net | Date: | Sun, 26 Mar 2006 22:26:01 +0000 |
| Subject: | note 50081 deleted from function.str-replace by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-106678@lists.php.net to get a copy of this message | ||
Note Submitter: cjo at ciqua dot org
----
In order to get rid of accents, we don't need to reach as far out as the ascii tables. HTML has
the lovely property that accents are added to the character X in the form &Xmodif; where modif
stands for the modification of the original character: acute, grave, uml, etc.
There are far fewer accents than accented letters so this should do the trick whether or not it is
intended for HTML or not:
function replace_accents($in_string)
{
$out_string = htmlentities($in_string);
$out_string = str_replace("uml;", "", $out_string);
$out_string = str_replace("acute;", "", $out_string);
$out_string = str_replace("grave;", "", $out_string);
$out_string = str_replace("cedil;", "", $out_string);
$out_string = str_replace("ring;", "", $out_string);
$out_string = str_replace("circ;", "", $out_string);
$out_string = str_replace("tilde;", "", $out_string);
$out_string = str_replace("lig;", "", $out_string);
$out_string = str_replace("slash;", "", $out_string);
$out_string = str_replace("&", "", $out_string);
return $out_string;
}
The function above assumes there are only letter in the input (no ampersand, < and >, quotes,
etc). I hope this helps!