
当解码的string有BOM头的时候json_decode会解析失败,我们需先去除BOM头。函数如下:
function removeBOM($str = '')
{
if (substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
$str = substr($str, 3);
}
return $str;
}
其他方式:
$result = trim($str, "\xEF\xBB\xBF");
print_r(json_decode($str, true));
exit;
$result = @iconv("UTF-8", "GBK//IGNORE", $str);
$result = @iconv("GBK", "UTF-8//IGNORE", $str);
print_r(j......