PHP Chinese processing tips _ PHP Tutorial

Source: Internet
Author: User
PHP Chinese processing skills. 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. After a day of online competition, 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 );
}

Bytes. For AJAX or Flash applications, submitting Chinese content to the background involves encoding and decoding (encode, decode) and conversion of encoding formats. Online...

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.