Home > Backend Development > PHP Tutorial > escape and urldecode_PHP tutorial

escape and urldecode_PHP tutorial

WBOY
Release: 2016-07-13 10:58:36
Original
943 people have browsed it

The example in the comments comes from http://cn.php.net/urldecode, but when the Chinese escape-processed string is executed this function, the returned Chinese UTF-8 encoding is returned.

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/631987.htmlTechArticle from http://cn.php.net/urldecode The example in the comment, but the Chinese version has been escaped If this function is executed on a string, the Chinese UTF-8 encoding will be returned. function unicode_urldecode($url...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template