PHP decrypts Unicode and escape encrypted string

Source: Internet
Author: User
Tags chr utf 8

In the JSON does not support Chinese, use it to send Chinese data will appear data loss or garbled, must be sent before the transmission of the string to encode, because the transmission in the past need to use JS data analysis, considering the JS has unescape function, so if there is an escape function in PHP, Encode the data and decode it with unescape on the client, which is much more convenient.

This article is for you to share a PHP decryption Unicode and escape cryptographic string function

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 This is the

Search on the Internet, a lot of PHP implementation of the Escape function, the same

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16 function Phpescape ($str) {Preg_match_all ("/[x80-xff].| [x01-x7f]+/", $str, $NEWSTR); $ar = $newstr [0]; foreach ($ar as $k => $v) {if (Ord ($ar [$k]) >=127) {$tmpString =bin2hex (iconv ("GBK", "ucs-2", $v)); if (!eregi ("WIN", Php_os)) {$tmpString = substr ($tmpString, 2,2). substr ($tmpString, 0,2);} $reString. = "%u". $tmpString; else {$reString. = Rawurlencode ($v);}} return $reString; }

The above mentioned is the entire content of this article, I hope you can enjoy.

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.