PHP 无法正常json_decode的解决
php 无法正常解析json字符串了,原因很可能是因为编码
<?php
mb_internal_encoding('UTF-8');
$str = file_get_contents("http://localhost/json.php");
var_dump(json_decode(trimUTF8BOM($str)));
function trimUTF8BOM($data){
if(substr($data, 0, 3) == pack('CCC', 239, 187, 191)) {
return substr($data, 3);
}
return $data;
}
?>
mb_internal_encoding('UTF-8');
$str = file_get_contents("http://localhost/json.php");
var_dump(json_decode(trimUTF8BOM($str)));
function trimUTF8BOM($data){
if(substr($data, 0, 3) == pack('CCC', 239, 187, 191)) {
return substr($data, 3);
}
return $data;
}
?>
使用这个函数过滤点bom