For AJAX or Flash applications, submitting Chinese content to the background involves encoding and decoding (encode, decode) and conversion of encoding formats. After a day, I came up with an eye.
For AJAX or Flash applications, submitting Chinese content to the background involves encoding and decoding (encode, decode) and conversion of encoding formats.
We recommend that you do not use the escape function on the PHP end on the internet. it filters out the English when both Chinese and English are mixed. I have been puzzled for a long time. we recommend using unicode_urldecode.
The conversion of the encoding format mainly involves data storage and client return, which can be done with iconv. this function seems to be used for reference in C ++.
The code is as follows:
Function unicode_urldecode ($ url)
{
Preg_match_all ('/% u ([[: alnum:] {4})/', $ url, $ );
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 );
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.