Php decoding js functions using escape transcoding

Source: Internet
Author: User
Php decoding js uses the escape transcoding function *** and jsunescape function to decode escape-encoded data * @ param $ str * functionunescape scape ($ str) {$ ret; $ lenstrlen ($ str); for ($ i0; $ I & lt; $ len; $ I ++) {function for decoding js code using escape transcoding in php

/*** Function and js Scape function to decode escape encoded data * @ param $ str */function unescape ($ str) {$ ret = ''; $ len = strlen ($ str); for ($ I = 0; $ I <$ len; $ I ++) {if ($ str [$ I] = '%' & $ str [$ I + 1] = 'u ') {$ val = hexdec (substr ($ str, $ I + 2, 4); if ($ val <0x7f) $ ret. = chr ($ val); else if ($ val <0x800) $ ret. = chr (0xc0 | ($ val> 6 )). chr (0x80 | ($ val & 0x3f); else $ ret. = chr (0xe0 | ($ val> 12 )). chr (0x80 | ($ val> 6) & 0x3f )). chr (0x80 | ($ val & 0x3f); $ I + = 5;} else if ($ str [$ I] = '%') {$ ret. = urldecode (substr ($ str, $ I, 3); $ I + = 2;} else $ ret. = $ str [$ I];} return $ ret ;} /*** function: js escape php implementation * @ param $ string the sting want to be escaped * @ param $ in_encoding * @ param $ out_encoding */function escape ($ string, $ in_encoding = 'utf-8', $ out_encoding = 'ucs-2') {$ return = ''; if (function_exists ('MB _ get_info ')) {for ($ x = 0; $ x <mb_strlen ($ string, $ in_encoding); $ x ++) {$ str = mb_substr ($ string, $ x, 1, $ in_encoding); if (strlen ($ str)> 1) {// multi-byte character $ return. = '% u '. strtoupper (bin2hex (mb_convert_encoding ($ str, $ out_encoding, $ in_encoding);} else {$ return. = '% '. strtoupper (bin2hex ($ str) ;}} return $ return ;}

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.