<?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