This is one collected a long time ago. I don't know who wrote it, but there is no problem after testing ~
JavaScript code
Copy codeThe 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) // else -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 codeThe Code is as follows:
% U6D4B % u8BD5www.jb51.net % 22% 22% 27% 27% 3C % 3E % 26% 26
After decoding:
Copy codeThe Code is as follows:
Test www.jb51.net "" ''<> &&