PHP json_encode Incompatible Json_unescaped_unicode solution, jsonencodeunicode_php Tutorial

Source: Internet
Author: User

PHP Json_encode incompatible with Json_unescaped_unicode solutions, Jsonencodeunicode


PHP5.4 support Json_unescaped_unicode This parameter, this parameter is to let Chinese characters in Json_encode without escaping, reduce the amount of data transfer. But in the PHP5.3, you have to write a function to achieve, the following is the workaround:

/*** JSON encoding of variables * @param mixed value to encode value, except for resource type, can be any data type, the function will only accept UTF-8 encoded data * @return String return value The JSON form of the value */function json_encode_ex ($value) {if (Version_compare (php_version, ' 5.4.0 ', ' < ')) {  $str = Json_encode ($value);  $str = Preg_replace_callback (         "#\\\u ([0-9a-f]{4}) #i",         function ($matchs)         {           return iconv (' Ucs-2be ', ' UTF-8 ', pack (' H4 ', $matchs [1]));         },          $str         );  return $str; } else {  return Json_encode ($value, Json_unescaped_unicode);}}

Determine the version of PHP, if less than 5.4 use a custom function to implement, if the version 5.4 and later use Json_unescaped_unicode.

The above is the PHP json_encode incompatible Json_unescaped_unicode solution, I hope to give you a reference to learn more PHP syntax, we can pay attention to the "PHP5 online manual", but also hope that we support a lot of help the home.

http://www.bkjia.com/PHPjc/1133040.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133040.html techarticle PHP json_encode incompatible with Json_unescaped_unicode solution, Jsonencodeunicode PHP5.4 support Json_unescaped_unicode This parameter, This parameter is when the Chinese characters are json_encode ...

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