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