Home >php教程 >PHP源码 >json_encode不支持中文解决方法

json_encode不支持中文解决方法

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:27:591010browse
<script>ec(2);</script>

/************************************************************** 

02  * 

03  *    使用特定function对数组中所有元素做处理 

04  *    @param    string    &$array        要处理的字符串 

05  *    @param    string    $function    要执行的函数 

06  *    @return boolean    $apply_to_keys_also        是否也应用到key上 

07  *    @access public 

08  * 

09  *************************************************************/

10 function arrayRecursive(&$array, $function, $apply_to_keys_also = false) 

11 { 

12     foreach ($array as $key => $value) { 

13         if (is_array($value)) { 

14             arrayRecursive($array[$key], $function, $apply_to_keys_also); 

15         } else { 

16             $array[$key] = $function($value); 

17         } 

18   

19         if ($apply_to_keys_also && is_string($key)) { 

20             $new_key = $function($key); 

21             if ($new_key != $key) { 

22                 $array[$new_key] = $array[$key]; 

23                 unset($array[$key]); 

24             } 

25         } 

26     } 

27 } 

28   

29 /************************************************************** 

30  * 

31  *    将数组转换为JSON字符串(兼容中文) 

32  *    @param    array    $array        要转换的数组 

33  *    @return string        转换得到的json字符串 

34  *    @access public 

35  * 

36  *************************************************************/

37 function JSON($array) { 

38     arrayRecursive($array, 'urlencode', true); 

39     $json = json_encode($array); 

40     return urldecode($json); 

41 }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn