php教程 json中文乱码处理方法
网页特效客户端对中文的处理是使用utf-8内码的,并且json对中文的处理也是
使用utf-8,因此,ajax->php的时候,php需要utf8->gbk;php处理好后,在交给
json函数处理之前需要gbk->utf8,然后将结果php->ajax。
$code = json_encode($str);
$code = preg_replace("#u([0-9a-f]+)#ie", "iconv('ucs-2', 'utf-8',
pack('h4', '1'))", $code);
?>
json_encode() 给含有中文的内容进行编码时,会出现类似于u5c71u4e1c这样的
代码,虽然使用jquery或者json_decode()进行解码的时候
下面看个实例
$json = array (
0 =>
array (
'id' => '13',
'name' => '乒乓球',
),
1 =>
array (
'id' => '17',
'name' => '篮球',
)
)
?>
encode_json进行编码的话,输出结果是本篇文章来源于:开发学院
[{"id":"13","name":null}
,{"id":"13","name":null}]
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.
