Chinese processing in PHP is always not so perfect often encountered in Chinese processing when garbled or empty problem, the following I also encountered the same problem in JSON processing, and then tidy up a perfect solution json_encode Chinese garbled or empty program class.
The code is as follows |
Copy Code |
/************************************************************** * * Processing of all elements in an array using a specific function * @param string & $array strings to be processed * @param string $function the function to execute * @return Boolean $apply _to_keys_also is also applied to the key * @access Public * *************************************************************/ Function arrayrecursive (& $array, $function, $apply _to_keys_also = False) { static $recursive _counter = 0; if (+ + $recursive _counter > 1000) { Die (' Possible deep recursion attack '); } foreach ($array as $key = = $value) { if (Is_array ($value)) { Arrayrecursive ($array [$key], $function, $apply _to_keys_also); } else { $array [$key] = $function ($value); } if ($apply _to_keys_also && is_string ($key)) { $new _key = $function ($key); if ($new _key! = $key) { $array [$new _key] = $array [$key]; Unset ($array [$key]); } } } $recursive _counter--; } /************************************************************** * * Convert Array to JSON string (Chinese compatible) * @param array $array to convert * JSON string to be converted @return string * @access Public * *************************************************************/ function JSON ($array) { Arrayrecursive ($array, ' UrlEncode ', true); $json = Json_encode ($array); Return UrlDecode ($json); } $array = array ( ' Name ' = ' and ' ' Age ' =>24 ); echo JSON ($array); |
http://www.bkjia.com/PHPjc/632709.html www.bkjia.com true http://www.bkjia.com/PHPjc/632709.html techarticle Chinese processing in PHP is always not so perfect often encounter Chinese processing when garbled or empty problems, the following I also encountered the same problem in the JSON processing, and then finishing a perfect solution ...