I'm trying to do accented character replacement in PHP but get funky results, my guess being because i'm using a UTF-8 string and str_replace can't properly handle multi-byte strings..
$accents_search = array('á','à','a','?','a','?','?','á','à','?','?','?','é','è',
'ê','?','é','è','ê','?','í','ì','?','?','í','ì','?','?','?','ò','ó','?','?','o','?',
'?','ó','ò','?','?','ú','ù','?','ú','ù','?','?','?','?','?');
$accents_replace = array('a','a','a','a','a','a','a','A','A','A','A','A','e','e',
'e','e','E','E','E','E','i','i','i','i','I','I','I','I','oe','o','o','o','o','o','o',
'O','O','O','O','O','u','u','u','U','U','U','c','C','N','n');
$str = str_replace($accents_search, $accents_replace, $str);
Results I get:
?rjan Nilsen -> ?orjan Nilsen
Expected Result:
?rjan Nilsen -> Orjan Nilsen
Edit: I've got my internal character handler set to UTF-8 (according to mb_internal_encoding()), also the value of $str is UTF-8, so from what I can tell, all the strings involved are UTF-8. Does str_replace() detect char sets and use them properly?
See Question&Answers more detail:
os