Here, it is generally necessary to pre-encode the normal string into a format that the JavaScript unescape () function can interpret, and in PHP, for example, you can use the following function to implement the same functionality as the Escape () function in javascript:
Copy CodeThe code is as follows:
function Escapetohex ($string, $encoding = UTF-8) {
$return =;
for ($x = 0; $x < Mb_strlen ($string, $encoding); $x + +) {
$str = Mb_substr ($string, $x, 1, $encoding);
if (strlen ($STR) > 1) {//multibyte character
$return. =%u. Strtoupper (Bin2Hex (mb_convert_encoding ($str, UCS-2, $encoding)));
} else {
$return. =%. Strtoupper (Bin2Hex ($STR));
}
}
return $return;
}
?>
Suppose we want to hide the following address: Http://www.dirk.sh/assets/uploaded/thisistest.pdf
We can use the following script to implement:
Copy CodeThe code is as follows:
Please include the Escapetohex () function definition yourself
$test = document.write (\test\);
echo;
?>
If you look at the source code of the page, you will see (because it is too long, so you have a manual branch, the actual result should be a complete line):
Copy CodeThe code is as follows:
The page displayed in the browser is not the same as the normal HTML.
Note:
1, the second parameter of the Escapetohex () function ($encoding) represents the encoding of the string that you pass in, the default is UTF-8, if you use other encodings, you should explicitly specify in the calling function;
2, Unescape () is objected to in the ECMAScript V3 specification, the specification recommends using the new alternative function decodeuricomponent (), but I have been tested to find that decodeuricomponent () The function has problems with multibyte character processing, so the unescape () function is still used.
3, in principle, the above method is only to prevent search crawlers to get the resource address you think you need to keep confidential, browse the page under Javascript-enabled browser, and see the rendering is identical without enabling this protection mechanism.
http://www.bkjia.com/PHPjc/322351.html www.bkjia.com true http://www.bkjia.com/PHPjc/322351.html techarticle here, it is generally necessary to pre-encode the normal string into a JavaScript unescape () function can be interpreted by the format, in PHP, for example, you can use the following functions to implement JavaScript ESCAP ...