Reputation: 53
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.
Upvotes: 5
Views: 11426
Reputation: 633
PHP's transliterator_transliterate()
function can convert accented characters to their ASCII equivalents.
$string = "Café Déjà vu Résumé naïve façade";
$converted = transliterator_transliterate('Any-Latin; Latin-ASCII', $string);
echo $converted; // Output: "Cafe Deja vu Resume naive facade"
Explanation
You must install the php-intl Extension
Upvotes: 0
Reputation: 168853
See the php manual page for strtr()
The examples on this page deal with exactly your situation.
Hope that helps.
Upvotes: 2
Reputation: 10643
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);
}
Upvotes: 5