PHP Chinese processing Skills _php Tutorial

Source: Internet
Author: User
It took a day to make a point.
Do AJAX applications or flash applications, submit Chinese content to the background, involving encoding and decoding (encode, decode) and encoding format conversion.
The PHP end of the Internet unescape function is recommended not to use, it mixed in English and Chinese in the English filter out, I was inexplicably n long Ah, suggested with Unicode_urldecode this.
And then the conversion of the encoding format, which mainly involves the storage of data and the return of the client, with Iconv, this function seems to be from the C + + reference.
Copy CodeThe 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 (+ ($dec% 64));
}
Else
{
$utf = Chr (224 + (($dec-($dec% 4096))/4096);
$utf. = Chr ((($dec% 4096)-($dec% 64))/64);
$utf. = Chr (+ ($dec% 64));
}
$url = Str_replace ('%u '. $uniord, $utf, $url);
}
Return UrlDecode ($url);
}

http://www.bkjia.com/PHPjc/321701.html www.bkjia.com true http://www.bkjia.com/PHPjc/321701.html techarticle It took a day to make a point. Do AJAX applications or flash applications, submit Chinese content to the background, involving encoding and decoding (encode, decode) and encoding format conversion. Online ...

  • Related Article

    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.