r/PHPhelp • • Jan 30 '20

Encoding issue, trying to replace strings but getting a way different result

<?php
function Utf8_ansi($valor) {

    $utf8_ansi2 = array(
    "\u00c0" =>"À",
    "\u00c1" =>"Á",
    "\u00c2" =>"Â",
    "\u00c3" =>"Ã",
    "\u00c4" =>"Ä",
    "\u00c5" =>"Å",
    "\u00c6" =>"Æ",
    "\u00c7" =>"Ç",
    "\u00c8" =>"È",
    "\u00c9" =>"É",

return strtr($valor, $utf8_ansi2);      

}

$test='\u00e9", ';

echo Utf8_ansi($test);   

?>

My output is és",

Any ideas?

7 Upvotes

4 comments sorted by

View all comments

1

u/lchoate Jan 30 '20
 function Utf8_ansi($valor) {

    $utf8_ansi2 = [
    "\u00c0" =>'À',
    "\u00c1" =>"Á",
    "\u00c2" =>"Â",
    "\u00c3" =>"Ã",
    "\u00c4" =>"Ä",
    "\u00c5" =>"Å",
    "\u00c6" =>"Æ",
    "\u00c7" =>"Ç",
    "\u00c8" =>"È",
    '\u00c9' =>'É',
    ];

return strtr($valor, $utf8_ansi2);      

}

$test='\u00c9';

echo Utf8_ansi($test);