admin管理员组文章数量:1550647
simplexml_load_string(): Entity: line 2: parser error : Input is not proper UTF-8, indicate encoding !
出现此错误的原因是:
json_decode的坑 仅仅支持utf-8编码的字符
进行转码处理
$str字符串
把$beforeEncode编码转变为$afterEncode
原理:验证字符串编码是否为$beforeEncode,如果是就转变为$afterEncode,如果不是$beforeEncode编码格式,那么查询当前字符串编码格式,然后在转为$afterEncode
array("ASCII","UTF-8","GB2312","GBK","BIG5")自己可以扩充此数组中的编码
function iconvStr($str,$beforeEncode,$afterEncode){
$postXml = '';
$encode = mb_detect_encoding($str, array("ASCII","UTF-8","GB2312","GBK","BIG5"));
if($encode == $beforeEncode){
$postXml = iconv($beforeEncode,$afterEncode,$str);
}else{
$postXml = iconv($encode,$afterEncode,$str);
}
return $postXml;
}
本文标签: simplexmlloadstringentityPHPjsonError
版权声明:本文标题:php json simplexml_load_string(),simplexml_load_string(): Entity: line 2: parser error : Input is no... 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1727247885a1104858.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论