Home > Backend Development > PHP Tutorial > PHP correctly decodes characters encoded by escape in javascript_PHP tutorial

PHP correctly decodes characters encoded by escape in javascript_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-21 15:41:29
Original
1046 people have browsed it

This is one I collected a long time ago. I don’t know who wrote it, but there is no problem after testing~
JavaScript code

Copy code The code is as follows:

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;
}

After escape encoding:
Copy code The code is as follows:

%u6D4B%u8BD5www.jb51.net%22%22%27%27%3C%3E%26%26

After decoding:
Copy code The code is as follows:

Test www.jb51.net""''< ;>&&

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321170.htmlTechArticleThis is one I collected a long time ago. I don’t know who wrote it, but there is no problem after testing ~ JavaScript code copy The code is as follows: function phpUnescape($escstr) { preg_match_all("/%u[...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template