Sep
21
echo unescape('%u82F9%u679C,%u82F9%u679C,否;%u6854%u5B50,%u6854%u5B50,否');
输出:苹果,苹果,否;桔子,桔子,否
输出:苹果,苹果,否;桔子,桔子,否
PHP代码:
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|&#x.{4};|&#d+;|&#d+?|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4)));
elseif(substr($v,0,3) == "&#x")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "&#") {
$ar[$k] = iconv("UCS-2","GBK",pack("n",preg_replace("/[^d]/","",$v)));
}
}
return join("",$ar);
}