这次给大家带来PHP+JSON输出汉字,PHP+JSON输出汉字的注意事项有哪些,下面就是实战案例,一起来看一下。
解决方法一:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php
function Notice(){
include './ include /conn.php';
$sql_notice =
mysql_query
('SELECT * FROM gg_notice where enable = "1" limit 0,10');
$notice =
mysql_fetch_array
( $sql_notice , MYSQL_ASSOC);
$str = json_encode( $notice );
return preg_replace( "#\\\u([0-9a-f]{4})#ie" , "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))" , $str );
}
?>
|
Copy after login
另外从网上搜索到的其他方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?php
class Json_Helper {
public static function encode( $str ){
$json = json_encode( $str );
return preg_replace( "#\\\u([0-9a-f]{4})#ie" , "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))" , $json );
}
public static function decode( $str ) {
return json_decode( $str );
}
}
?>
|
Copy after login
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
jQuery做出垂直半透明手风琴效果
jquery实现导航菜单鼠标提示功能
The above is the detailed content of PHP+JSON output Chinese characters. For more information, please follow other related articles on the PHP Chinese website!