Home > Backend Development > PHP Tutorial > php json_encode中文和斜杠

php json_encode中文和斜杠

WBOY
Release: 2016-06-06 20:12:16
Original
1402 people have browsed it

php中json_encode有几个常量
JSON_UNESCAPED_UNICODE //中文不转为unicode
JSON_UNESCAPED_SLASHES //不转义反斜杠

现在我的需求是,要上面2个常量同时生效,应该怎么做啊?

PS: @dinoxxx 和 @咪蛾 说的两种方式测试了都有效
因为 @dinoxxx 先回答,所以采纳了ta,谢谢大家!

回复内容:

php中json_encode有几个常量
JSON_UNESCAPED_UNICODE //中文不转为unicode
JSON_UNESCAPED_SLASHES //不转义反斜杠

现在我的需求是,要上面2个常量同时生效,应该怎么做啊?

PS: @dinoxxx 和 @咪蛾 说的两种方式测试了都有效
因为 @dinoxxx 先回答,所以采纳了ta,谢谢大家!

这俩参数中间加个“|”
在PHP内部都是用1

JSON_UNESCAPED_UNICODE 和 JSON_UNESCAPED_SLASHES 都是常量
JSON_UNESCAPED_UNICODE = 256
JSON_UNESCAPED_SLASHES = 64
JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES = 320
两个同时生效你可以用

<code class="php"><?php $arr = array('test'=>'测试中文和/同时生效');
json_encode($arr,320);</code>
Copy after login

常量对照可在http://php.net/manual/en/json.constants....查看

base64_encode

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template