您好,欢迎访问一九零五行业门户网

PHP+AJAX中文乱码问题解决方法

ajax|解决|问题|中文乱码
在php从ajax的来的数据进行转化函数
function utf8rawurldecode ($source) {
    $decodedstr = ;
    $pos = 0;
    $len = strlen ($source);
     while ($pos $len) {
        $charat = substr ($source, $pos, 1);
         if ($charat == '%') {
            $pos++;
            $charat = substr ($source, $pos, 1);
             if ($charat == 'u') {
                // we got a unicode character
                $pos++;
                $unicodehexval = substr ($source, $pos, 4);
                $unicode = hexdec ($unicodehexval);
                $entity = . $unicode . ';';
                $decodedstr .= utf8_encode ($entity);
                $pos += 4;
             }
             else {
                // we have an escaped ascii character
                $hexval = substr ($source, $pos, 2);
                $decodedstr .= chr (hexdec ($hexval));
                $pos += 2;
             }
         } else {
            $decodedstr .= $charat;
            $pos++;
         }
     }
     return $decodedstr;
}
运用以下函数
$formname=utf8rawurldecode($formname);
iconv(utf-8,gb2312,$formname);
因为ajax通过escape转换数据加密了数据
================================================
查资料显示可以用
$formname=mb_convert_encoding($formname,gb2312,utf-8);
其它类似信息

推荐信息