List Info

Thread: note 68480 added to function.str-replace




note 68480 added to function.str-replace
user name
2006-07-28 21:11:27
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.p
hp.net/note/edit/68480
Del: integrated  -- ht
tp://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://m
aster.php.net/note/delete/68480/spam
Del: non-english -- h
ttp://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://ma
ster.php.net/manage/user-notes.php

-- 
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )