Posted in PHP onJanuary 28, 2010
这是很久以前收集的一个,不知道谁写的了,但经过测试没有问题~
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%u8BD53water.com%22%22%27%27%3C%3E%26%26
解码后:
测试3water.com""''<>&&
php 正确解码javascript中通过escape编码后的字符
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@