Home > Backend Development > PHP Tutorial > PHP Chinese processing skills_PHP tutorial

PHP Chinese processing skills_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:38:45
Original
942 people have browsed it

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);
}

www.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 of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template