在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");
中国最大的web开发资源网站及技术社区,新闻热点
疑难解答