PHP下escape解码函数的实现方法
前端之家收集整理的这篇文章主要介绍了
PHP下escape解码函数的实现方法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
GB2312编码:
<div class="codetitle"><a style="CURSOR: pointer" data="79948" class="copybut" id="copybut79948" onclick="doCopy('code79948')"> 代码如下:
<div class="codebody" id="code79948">
function unescape($str) {
$str = rawurldecode($str);
preg_match_all("/%u.{4}|&#x.{4};|&#d+;|.+/U",$str,$r);
$ar = $r[0];
foreach($ar as $k=>$v) {
if(substr($v,2) == "%u")
$ar[$k] = iconv("UCS-2","GBK",pack("H4",substr($v,-4)));
elseif(substr($v,3) == "&#x")
$ar[$k] = iconv("UCS-2",3,-1)));
elseif(substr($v,2) == "&#") {
$ar[$k] = iconv("UCS-2",pack("n",2,-1)));
}
}
return join("",$ar);
}