note 50081 added to function.str-replace

From: Date: Thu, 17 Feb 2005 12:29:46 +0000
Subject: note 50081 added to function.str-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-85161@lists.php.net to get a copy of this message
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! ---- Manual Page -- http://www.php.net/manual/en/function.str-replace.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50081 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50081&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50081&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50081&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50081&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50081&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50081&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85161) next »