但是,有一点需要注意的地方是,urldecode() 和 rawurldecode() 解码出的字符串是 UTF-8格式的编码,如果URL中含有中文的话,而页面设置又不是 UTF-8 的话,则要把解码出的字符串进行转换,才能正常显示!
还有一个问题,就是所获得的 URL 不是 %%nn n={0..F} 的格式,而是 %unnnn n={0..F} 的格式,这时候再使用 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;
}
http://www.bkjia.com/PHPjc/322095.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/322095.htmlTechArticle下面是详细解释:///\\\ string urlencode ( string str) 返回字符串,此字符串中除了 -_. 之外的所有非字母数字字符都将被替换成百分号(%)后跟两...