Replace é with e in PHP
Hey, this is my first post on stackoverflow.
I'm trying to replace é with e and other similar special characters. I've开发者_如何学运维 tried str_replace() and converting it from UTF-8 to ASCII but nothing seems to work. When I convert it from UTF-8 to anything it just drops the é off. When I use str_replace() it never catches it and the é is still there.
I have a feeling something is wrong internally on our server because my friend tried str_replace() on his server and it worked fine.
Thanks,
Jason Tolhurst
$string = iconv('utf-8','ASCII//IGNORE//TRANSLIT',$string);
You can use htmlentities()
to convert é
to é
and then use a regex to pull out the first character after an ampersand.
function RemoveAccents($string) {
// From http://theserverpages.com/php/manual/en/function.str-replace.php
$string = htmlentities($string);
return preg_replace("/&([a-z])[a-z]+;/i", "$1", $string);
}
See the php manual page for strtr()
The examples on this page deal with exactly your situation.
Hope that helps.
精彩评论