最新消息: 新版网站上线了!!!

simplexml_load_string(): Entity: line 2: parser error : Input is not proper UTF-

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;

}


转载请注明:谷谷点程序 » simplexml_load_string(): Entity: line 2: parser error : Input is not proper UTF-