Home > Article > Web Front-end > PHP implementation code of escape and unescape functions in js_javascript skills
function phpescape($str)
{
$sublen=strlen($str);
$retrunString="";
for ($i=0;$i $tmpString=bin2hex(iconv("gb2312","ucs-2",substr ($str,$i,2)));
$retrunString.="%u".$tmpString;
runString.="%".dechex(ord($str[$i]));
🎜> 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] = iconv("UCS-2","GBK", pack ("h4", substr ($ v, -4));
Elseif (Substr ($ v, 0,3) == "")
$ AR [$ k] = iconvvvvvvvvvv ("UCS-2","GBK",pack("H4",substr($v,3,-1)));
elseif(substr($v,0,2) == "" ) {
$ar[$k] }
return join("",$ar);
}
?>