在php5.4版本之前如果想让json支持中文我们需要进行一些转换操作,如使用json_encode中文的话会转换成像\u4e2d\u6587类的编码了,但有了JSON_UNESCAPED_UNICODE之后直接不转码输出中文,下面我们给大家具体测试一下.
用PHP的json_encode来处理中文的时候,中文都会被编码,变成不可读的,类似”u***”的格式,还会在一定程度上增加传输的数据量,代码如下:
echo json_encode("中文"); //Output:"u4e2du6587"//phprm.com
这就让我们这些在天朝做开发的同学,很是头疼,有的时候还不得不自己写json_encode.
而在PHP5.4,这个问题终于得以解决,Json新增了一个选项:JSON_UNESCAPED_UNICODE, 故名思议,就是说,Json不要编码Unicode.看下面的例子,代码如下:
echo json_encode("中文", JSON_UNESCAPED_UNICODE); //Output: "中文"
怎么样,是不是让大家很开心的改动?Json在5.4还加入了:JSON_BIGINT_AS_STRING,JSON_PRETTY_PRINT,JSON_UNESCAPED_SLASHES等选项.
本文地址:
转载随意,但请附上文章地址:-)

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Notepad++7.3.1
Easy-to-use and free code editor

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

Dreamweaver CS6
Visual web development tools
