note 68480 added to function.str-replace
| From: | heavyraptor at osu1 dot php dot net | Date: | Fri, 28 Jul 2006 21:11:27 +0000 |
| Subject: | note 68480 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-115306@lists.php.net to get a copy of this message | ||
I had some problems with the function "remove_accents" by joaquin at metaltoad dot com.
The problem was that it changed every encoded char, even encoded chars like > (output was g,
because the first char after the & is taken).
I changed it a little bit, it works fine now.
<?php
function replace_accents($str) {
$str = htmlentities($str);
$str =
preg_replace('/&([a-zA-Z])(uml|acute|grave|circ|tilde);/','$1',$str);
return html_entity_decode($str);
}
?>
Example:
<?php
$str = "äöü ÃÃà à éè ÃÃà Text &%*'\\"
<>";
$str = replace_accents($str);
echo $str; // prints "aou AOU aee AEE Text &%*'" <>"
?>
Have fun
----
Server IP: 66.163.161.117
Probable Submitter: 84.73.156.125
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- http://master.php.net/note/edit/68480
Del: integrated -- http://master.php.net/note/delete/68480/integrated
Del: useless -- http://master.php.net/note/delete/68480/useless
Del: bad code -- http://master.php.net/note/delete/68480/bad+code
Del: spam -- http://master.php.net/note/delete/68480/spam
Del: non-english -- http://master.php.net/note/delete/68480/non-english
Del: in docs -- http://master.php.net/note/delete/68480/in+docs
Del: other reasons-- http://master.php.net/note/delete/68480
Reject -- http://master.php.net/note/reject/68480
Search -- http://master.php.net/manage/user-notes.php