EDIT
Now, I’ve figured out the correct, working answer based on the article I found. Here is it:
function unicode2utf8($str) {
$a=json_decode(str_replace("\n","<br>",'["'.$str.'"]'));
return str_replace("<br>","\n",$a[0]);
}
PHP:
echo unicode2utf8("Tom\u00e1nsson\n Eriksen\n Gilverto\n");
Output:
Tománsson
Eriksen
Gilverto
ORIGINAL
I’ve found an article about the same problem here ( http://www.welefen.com/php-unicode-to-utf8.html )
The solution is the following function
function unicode2utf8($str){
if(!$str) return $str;
$decode = json_decode($str);
if($decode) return $decode;
$str="["" . $str . '"]';
$decode = json_decode($str);
if(count($decode) == 1){
return $decode[0];
}
return $str;
}
I’ve tried it with
echo unicode2utf8("\u00e1");
Output:
á
8
solved “\u00e1n” to “á” in PHP [closed]