How to solve JSON_ERROR_UTF8 error in php json_decode?

后端 未结 5 2008
北恋
北恋 2020-11-27 17:46

I am trying this code

$json = file_get_contents(\"http://www.google.com/alerts/preview?q=test&t=7&f=1&l=0&e\");
print_r(json_decode(utf8_enc         


        
5条回答
  •  清酒与你
    2020-11-27 18:13

    The iconv function is pretty worthless unless you can guarantee the input is valid. Use mb_convert_encoding instead.

    mb_convert_encoding($value, "UTF-8", "auto");
    

    You can get more explicit than "auto", and even specify a comma-separated list of expected input encodings.

    Most importantly, invalid characters will be handled without causing the entire string to be discarded (unlike iconv).

提交回复
热议问题