PHP implementation echo json_encode correct display of Chinese characters

Source: Internet
Author: User

<?PHPHeader(' content-type:text/html; Charset=utf-8 ');/*function showmessage ($msg = ", $redirect =", $delay = 3) {if ($_get[' format '] = = ' json ') {$result = array (        ' msg ' = $msg, ' redirect ' = $redirect, ' delay ' and $delay);        echo Json_encode ($result);    Exit ();    } include ' message.php '; Exit ();} ShowMessage (' HelloWorld ', ' www.baidu.com ', 5);*//*$arr = Array (' Name ' = ' Shia ', ' age ' =>20); $jsonencode = Json_encode ($arr); Echo $jso Nencode;*/$array=Array    (         ' Title ' =Iconv("GB2312", "Utf-8//ignore", ' Here is the Chinese title '), ' body ' = ' abcd ... '    ); EchoJson_encode ($array);$text= "This is the Euro symbol ' € '.";Echo' Original: ',$text,Php_eol;Echo' Translit: ',Iconv("UTF-8", "Iso-8859-1//translit",$text),Php_eol;Echo' IGNORE: ',Iconv("UTF-8", "Iso-8859-1//ignore",$text),Php_eol;//Echo ' Plain: ', Iconv ("UTF-8", "iso-8859-1", $text), Php_eol;/************************************************************** * * Handle all elements in an array with a specific function * @param string        & $array The string to be processed * @param string $function the function to execute * @return Boolean $apply _to_keys_also is also applied to the key * @access public * *************************************************************/functionArrayrecursive (&$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--;} /************************************************************** * * Converts an array to a JSON string (Chinese-compatible) * @param array $arra Y the array to convert * @return the JSON string converted from String * @access public * ******************************************** *****************/functionJSON ($array) {arrayrecursive ($array, ' UrlEncode ',true); $json= Json_encode ($array); return UrlDecode($json);}$array 1=Array       (          ' Name ' = ' Shia ', ' age ' =>20       );$array=Array       (          ' Name ' + =$array 1, ' Age ' =>20       );EchoJSON ($array);?>

PHP implementation echo json_encode correct display of Chinese characters

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.