JS function PHP Custom Function Implementation JS Escape Method Example

Source: Internet
Author: User
This article describes the PHP custom function implementation of JS escape method. Share to everyone for your reference, as follows:

PHP functionfunction Escape ($string) {$n = $bn = $tn = 0;    $output = ";    $special = "-_.+@/*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";        while ($n < strlen ($string)) {$ascii = Ord ($string [$n]); if ($ascii = = 9 | | $ascii = = 10 | | (<= $ascii && $ascii <= 126))        {$tn = 1; $n + +;        } elseif (194 <= $ascii && $ascii <= 223) {$tn = 2; $n + = 2;        } elseif (224 <= $ascii && $ascii <= 239) {$tn = 3; $n + = 3;        } elseif (<= $ascii && $ascii <= 247) {$tn = 4; $n + = 4;        } elseif (248 <= $ascii && $ascii <= 251) {$tn = 5; $n + = 5;        } elseif ($ascii = = 252 | | $ascii = = 253) {$tn = 6; $n + = 6;        } else {$n + +;        } $singleStr = substr ($string, $bn, $tn);        $charVal = Bin2Hex (Iconv (' utf-8 ', ' ucs-2 ', $singleStr)); if (Base_convert ($charVal, 0xff) >{if (!preg_match ("/win/i", php_os)) $charVal = substr ($charVal, 2, 2). substr ($charVal, 0, 2); $output. = '%u '.        $charVal;            } else {if (false!== Strpos ($special, $SINGLESTR)) $output. = $singleStr; else $output. = "%".        Dechex (Ord ($string [$bn]);    } $bn = $n; } return $output;}

For more information about PHP related content readers can view the topic: "PHP coding and transcoding Operation skills Summary", "PHP String Usage Summary", "PHP array" operation skill Daquan, "PHP Sorting algorithm Summary", " PHP common traversal algorithm and skills summary, "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", "PHP Math Skills Summary", "PHP Regular Expression Usage summary", "PHP operation and operator usage Summary" and "PHP common database Operation Skills Summary"

I hope this article is helpful to you in PHP programming.

The above introduces the JS function PHP custom function to implement JS's Escape method example, including the JS function aspects, I hope that the PHP tutorial interested in a friend helpful.

  • 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.