It took me a whole day to figure it out.
Making AJAX applications or Flash applications and submitting Chinese content to the backend involves encoding, decoding (encode, decode) and encoding format conversion.
It is recommended not to use the escape unescape function on the PHP side on the Internet. It filters out the English when Chinese and English are mixed. I was confused for a long time. It is recommended to use unicode_urldecode.
Then there is the conversion of encoding format, which mainly involves data storage and client return. It can be done with iconv. This function seems to be borrowed from C++.
Copy code The code is as follows:
function unicode_urldecode($url)
{
preg_match_all('/% u([[:alnum:]]{4})/', $url, $a);
foreach ($a[1] as $uniord)
{
$dec = hexdec($ uniord);
$utf = '';
if ($dec < 128)
{
$utf = chr($dec);
}
else if ($ dec < 2048)
{
$utf = chr(192 + (($dec - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
else
{
$utf = chr(224 + (($dec - ($dec % 4096)) / 4096));
$utf . = chr(128 + ((($dec % 4096) - ($dec % 64)) / 64));
$utf .= chr(128 + ($dec % 64));
}
$url = str_replace('%u'.$uniord, $utf, $url);
}
return urldecode($url);
}
http://www.bkjia.com/PHPjc/321701.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321701.htmlTechArticleIt took me a day to figure out something. Making AJAX applications or Flash applications and submitting Chinese content to the backend involves encoding, decoding (encode, decode) and encoding format conversion. Online...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn