JavaScript 的 Unicode 格式 URL 编码的解码
转载
即 %uXXXX 格式的,看着很不爽。iconv UNICODE 居然还不行,得是 UNICODEBIG
[phpcode]
function fnJSUrlDecode($sOrg, $sCharset = "GBK") {
$sPattern = "/%u[0-9a-f]{4}/i";
preg_match_all($sPattern, $sOrg, $aOut);
$aSearch = array();
$aReplace = array();
foreach ($aOut[0] as $sValue) {
$aSearch[] = $sValue;
$aReplace[] = iconv("UNICODEBIG", $sCharset, pack("H*", substr($sValue, 2)));
}
$sOut = str_replace($aSearch, $aReplace, $sOrg);
return $sOut;
}
echo fnJSUrlDecode("word=%u6D4B%u8BD5%u6587%u5B57");
[/phpcode]