php json_encode 中文乱码的解决方法
来源:互联网 发布:重生之君颜网络剧免费 编辑:程序博客网 时间:2024/06/06 05:08
json_encode对中文的处理一直存在问题的:
1.不能处理GB编码,所有的GB编码都会替换成空字符.
2.utf8编码的中文被编码成unicode编码,相当于javascript的escape函数处理的结果.
为了能正确使用json:
首先,我应该在编码上采用utf8编码;
然后,再对json_encode的返回结果稍加处理。
$code = json_encode($str); //unicode编码的中文 $output = preg_replace("#\\\u([0-9a-f]+)#ie", "iconv('UCS-2', 'UTF-8', pack('H4', '\\1'))", $code); //utf8编码的中文
PS: 对于GB编码的中文,我们可以在编码时先转成UTF8编码,再进行编码,解码的时候再进行一个utf8 ->gb(iconv("utf-8","gb2312",$str))的转换就可以了。
0 0
- php json_encode 中文乱码的解决方法
- php json_encode 中文乱码的解决方法
- PHP json_encode中文乱码解决方法
- PHP json_encode中文乱码解决方法
- PHP json_encode中文乱码解决方法
- PHP json_encode中文乱码解决方法
- PHP json_encode中文乱码解决方法
- PHP json_encode中文乱码解决方法
- php json_encode 中文乱码解决方法
- php json_encode 中文乱码解决方法
- json_encode 中文乱码的解决方法
- php使用json_encode后出现中文乱码的解决方法
- PHP json_encode中文乱码解决方法--json乱码处理
- PHP,postgresQL,json_encode,sphinx 中文显示乱码解决方法总结
- PHP json_encode 函数中文乱码
- 最佳PHP json_encode将中文编码为UTF8的解决方法
- json_encode 不支持中文的解决方法
- PHP函数json_encode中文乱码解决
- 新手起家
- UML_China 软件开发
- 暖心
- linux下压缩文件的解压命令
- centos6.3 使用yum方式安装redis
- php json_encode 中文乱码的解决方法
- 中断服务程序
- 高性能网络编程七--tcp连接的内存使用
- MFCC(语音特征参数)
- js动态添加行保持jquery easyui 验证特效
- 每天都在纠结
- Live555 Streaming Media学习(一)——openRTSP分析
- Map 取出内容有用代码
- 计数排序