Implementation of Javascript escape () function code in PHP

Source: Internet
Author: User
In Javascript, you can use the escapeunescape () and eval_r () functions for simple transcoding to make normal URLs look weird, make those annoying search crawlers unable to identify the resources you want to hide. Generally, normal strings must be encoded into the format that can be interpreted by the JavaScript unescape () function. for example, you can use the following function to implement escape () in Javascript () functions are the same:
The 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) {// multi-byte characters
$ 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:
The code is as follows:
// Please include the escapeToHex () function definition by yourself
$ Test = document. write (\ test \);
Echo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.