Home > php教程 > php手册 > escape和urldecode

escape和urldecode

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 09:58:12
Original
1570 people have browsed it

来自 http://cn.php.net/urldecode 评论中的例子,但是中文经escape处理后的字符串再执行此函数,返回的是中文的utf-8编码.

function unicode_urldecode($url)
{
preg_match_all('/%u([[:alnum:]]{4})/', $url, $a);

foreach ($a[1] as $uniord)
{
$dec = hexdec($uniord);
$utf = '';

if ($dec {
$utf = chr($dec);
}
else if ($dec {
$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);
}

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template