0

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.

5
  • Can you give an example player name where the error occur?
    – sofl
    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 } May 22, 2014 at 12:51
  • when it is rendered on the browser it displays Júlio Cà May 22, 2014 at 12:56
  • 1
    Yes i saw. Seems indeed broken. Maybe this library could help you github.com/neitanod/forceutf8 see also here stackoverflow.com/questions/1344692/…
    – sofl
    May 22, 2014 at 12:57
  • possible duplicate of json_encode(): Invalid UTF-8 sequence in argument
    – Matt S
    Jul 22, 2015 at 19:12

1 Answer 1

2

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');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.