Json_encode does not support Chinese solutions-PHP source code

Source: Internet
Author: User
Ec (2 ); **************************************** * ********************* & nbsp; 02 & nbsp; * & nbsp; 03 & nbsp; * & nbsp; use a specific function to process all elements in the array & nbsp; 04 & nbsp; * & nbsp; @ param & nbsp; & script ec (2); script

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

02 *

03 * use a specific function to process all elements in the array

04 * @ param string & $ array the string to be processed

05 * @ param string $ function the function to be executed

06 * @ return boolean $ apply_to_keys_alsoApplicationTo the 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 * convert an array to a JSON string (compatible with Chinese characters)

32 * @ param array $ array to be converted

33 * @ return string the converted json string

34 * @ access public

35 *

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

37 function JSON ($ array ){

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

39 $ json = json_encode ($ array );

40 return urldecode ($ json );

41}

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.