I have list of player name. But the problem is the player name contains some non utf-8 characters. so i am having following error.
json_encode(): Invalid UTF-8 sequence in argument
i have used following code to overcome it, but it didn't work.
utf8_encode($player->name);
and
$player_name = iconv(mb_detect_encoding($player->name, mb_detect_order(), true), "UTF-8", $player->name);
thanks in advance.
asked May 22, 2014 at 12:45
user1795109
7262 gold badges6 silver badges14 bronze badges
-
Can you give an example player name where the error occur?sofl– sofl2014年05月22日 12:49:07 +00:00Commented May 22, 2014 at 12:49
-
this is the json working on the local pc. & it seems to have no problem. But on live server we encounter with the problem.{ "player_id" : 125, "player_name" : "J\u00c3\u0083\u00c2\u00balio C\u00c3...", "player_country" : "35", "player_country_name" : "Brazil", "player_team" : "Brasil", "player_role" : "Goalkeeper", "player_price" : 0, "substitute" : 0, "captain" : 1, "vice_captain" : 0 }user1795109– user17951092014年05月22日 12:51:29 +00:00Commented May 22, 2014 at 12:51
-
when it is rendered on the browser it displays Júlio CÃuser1795109– user17951092014年05月22日 12:56:27 +00:00Commented May 22, 2014 at 12:56
-
1Yes i saw. Seems indeed broken. Maybe this library could help you github.com/neitanod/forceutf8 see also here stackoverflow.com/questions/1344692/…sofl– sofl2014年05月22日 12:57:09 +00:00Commented May 22, 2014 at 12:57
-
possible duplicate of json_encode(): Invalid UTF-8 sequence in argumentMatt S– Matt S2015年07月22日 19:12:42 +00:00Commented Jul 22, 2015 at 19:12
1 Answer 1
Just had the same issue and was able to solve it by forcing UFT-8 with mb_convert_encoding():
$string = mb_convert_encoding($string,'UTF-8','UTF-8');
answered Feb 26, 2015 at 20:50
John Veldboom
2,28731 silver badges34 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-php