} 的格式,这时候再使用 urldecode() 和 rawurldecode() 是无法正确解码的,而要用下面这个函数才能正确解码:
复制代码 代码如下:
function utf8RawUrlDecode ($source)
{
$decodedStr = "";
$pos = 0;
$len = strlen ($source);
while ($pos < $len) {
$charAt = substr ($source, $pos, 1);
if ($charAt == ''%'') {
$pos++;
$charAt = substr ($source, $pos, 1);
if ($charAt == ''u'') {
// we got a unicode character
$pos++;
$unicodeHexVal = substr ($source, $pos, 4);
$unicode = hexdec ($unicodeHexVal);
$entity = "". $unicode . '';'';
$decodedStr .= utf8_encode ($entity);
$pos += 4;
}
else {
// we have an escaped ascii character
$hexVal = substr ($source, $pos, 2);
$decodedStr .= chr (hexdec ($hexVal));
$pos += 2;
}
} else {
$decodedStr .= $charAt;
$pos++;
}
}
return $decodedStr;
}