json_encode()解析json串中文乱码的问题
2017-09-25 本文已影响0人
丶Assassin丨
preg_replace未弃用可使用:
$jsonuni = json_encode($car[$line][$site]);
$json = preg_replace("#\\\u([0-9a-f]{4})#ie","iconv('UCS-2BE','utf-8',pack('H4','\\1'))",$jsonuni);
echo $json;
preg_replace 弃用后使用方法:
$jsonuni = json_encode($data);
$json = preg_replace_callback('/\\\\u([0-9a-f]{4})/i',create_function('$matches','return mb_convert_encoding(pack("H*", $matches[1]), "UTF-8", "UCS-2BE");'),$jsonuni);
echo $json;die;
php>5.4
json_encode($data,JSON_UNESCAPED_UNICODE);