Ajax| Solution | problem | Chinese garbled
Conversion functions in PHP from the data from 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 ;
}
Use the following functions
$formname =utf8rawurldecode ($formname);
Iconv ("UTF-8", "GB2312", $formname);
Because Ajax encrypts data by transforming data from escape
================================================
Check the data to show you can use
$formname =mb_convert_encoding ($formname, "GB2312", "UTF-8");