function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|.{4};|d+;|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u"){
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,-4)),"gb2312","UCS-2");
}elseif(substr($v,0,3) == ""){
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,3,-1)),"gb2312","UCS-2");
}elseif(substr($v,0,2) == "") {
$ar[$k] = mb_convert_encoding(pack("H4",substr($v,2,-1)),"gb2312","UCS-2");
}
}
return join("",$ar);
}
$str = '/?y=%u597D&m=%u554A&h=%20';
$query = parse_url($str,PHP_URL_QUERY);
parse_str($query);
echo unescape($y);
?>
$str="/?y=%u597D&m=%u554A&h=%20";
$result="";
if(preg_match('#y=(.+)&m=#isU',$str,$ma)){$result=unescape($ma[1]);}
echo $result;
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/(?:%u.{4})|.+/",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,0,2) == "%u" && strlen($v) == 6)
$ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,-4)));
}
return join("",$ar);
}
你这个应该是对url 的拆分,拆倒是能拆。不过意义不大啊