Note that when json_encode Chinese, the default is unicode encoding, if you want to become Chinese, you need to increase the parameter JSON_UNESCAPED_UNICODE
But the JSON_UNESCAPED_UNICODE parameter is only supported above php5.4
So you can use the following code:
function json_encode2($array) { if (version_compare(PHP_VERSION, ' 5.4.0 ' , ' < ' )){ $str = json_encode($array); $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($array, JSON_UNESCAPED_UNICODE); } }
Read More:
- [Solved] PHP post Datas json_decode Error: 4 JSON_ERROR_SYNTAX
- 404 solution for WordPress Chinese tag
- PHP Error Object of class mysqli could not be converted to string in
- Error during session start; please check your PHP and/or webserver log file and configure your PHP
- TP5 fuzzy Chinese characters error [How to Solve]
- [PHP] Solve the limitation of uploading files in nginx php 413 Request Entity Too Large
- PHP error in Windows: class’ mysqli ‘not found
- PHP php-config is not installed error in ubuntu 16 [How to Solve]
- PHP: How to parse MHT file into HTML
- PHP use __Sleep() and __wakeup() method serializes the object
- [Solved] PHP Fatal error: Uncaught Error: Class ‘Redis‘ not found in
- PHP: How to get the total number of data in the MySQL table (total number of rows)
- Mac: Where is php.ini Location
- composer Error: The requested PHP extension ext-bcmath * is missing from your system. Install or enable
- nginx.conf php-fpm.conf and php.ini Error among the three_ Differences and relations between log instructions
- PHP encryption 3DES error Call to undefined function: mcrypt_module_open() solution
- [Solved] PHP Fatal error: Uncaught Elasticsearch\Common\Exceptions\NoNodesAvailableException: No alive nodes
- Mac PHP Fatal error: Class ‘Memcache’ not found
- [Solved] PHP Error: Warning: file_get_contents(): Failed to enable crypto
- HTML + PHP inline execute JavaScript Error [How to Solve]