php json supports Chinese

巴扎黑
Release: 2016-11-24 10:58:16
Original
1181 people have browsed it

支持中文的 php json 函数

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

*

* Use a specific function to process all elements in the array

* @param string &$array The string to be processed

* @param string $function to be executed Function

* @return boolean $apply_to_keys_also Whether it is also applied to key

* @access public

*

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

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

{

    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]);

            }

        }

    }

}

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

*

* Convert array to JSON string (compatible with Chinese)

* @param array $array The array to be converted

* @return string The converted json character String

* @access public

*

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

function JSON($array) {

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

$json = json_encode($array);

return urldecode($json);

}


?>


Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!