php 正确解码javascript中通过escape编码后的字符
这是很久以前收集的一个,不知道谁写的了,但经过测试没有问题~
JavaScript代码
escape编码后:
解码后:
JavaScript代码
代码如下:
function phpUnescape($escstr) { preg_match_all("/%u[0-9A-Za-z]{4}|%.{2}|[0-9a-zA-Z.+-_]+/", $escstr, $matches); $ar = &$matches[0]; $c = ""; foreach($ar as $val) { if (substr($val, 0, 1) != "%") { $c .= $val; } elseif (substr($val, 1, 1) != "u") { $x = hexdec(substr($val, 1, 2)); $c .= chr($x); } else { $val = intval(substr($val, 2), 16); if ($val < 0x7F) // 0000-007F { $c .= chr($val); } elseif ($val < 0x800) // 0080-0800 { $c .= chr(0xC0 | ($val / 64)); $c .= chr(0x80 | ($val % 64)); } else // 0800-FFFF { $c .= chr(0xE0 | (($val / 64) / 64)); $c .= chr(0x80 | (($val / 64) % 64)); $c .= chr(0x80 | ($val % 64)); } } } return $c; }
escape编码后:
代码如下:
%u6D4B%u8BD5www.jb51.net%22%22%27%27%3C%3E%26%26
解码后:
代码如下:
测试www.jb51.net""''<>&&
相关推荐
xzkjgw 2020-03-06
zyyjay 2020-01-22
zhglinux 2020-01-17
xsjezp 2008-06-20
kevinweijc 2013-06-04
anzhen0 2008-10-07
whyname 2017-05-18
别时茫茫 2012-08-27
一叶不知秋 2019-05-28
manlsq 2018-09-20
奇迹的黄昏 2016-04-25
楼上小宇home 2010-03-16
逍遥友 2010-03-16
lidongliang 2013-05-14
veforever 2017-08-06
小菜鸟的代码世界 2017-06-20