Blogger Information
Blog 29
fans 0
comment 0
visits 34974
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php中让json_encode不自动转义斜杠“/”
小臣
Original
857 people have browsed it

最近将使用爬虫爬取的链接保存到 mysql 数据库中时,发现我将链接使用 json_encode 保存时候,在数据库中却显示了转义字符,我并不需要这转义的,看起来不清晰而且占用存储空间。

本文说说如何使用 json_encode 不自动转义斜杠。

<?php
/*
php中让json_encode不自动转义斜杠“/”
 */
$a = array(
	'http://www.baidu.com',
	'http://www.baidu.com',
	'http://www.baidu.com',
	'http://www.baidu.com',
	'http://www.baidu.com'
);
// 其一 正则替换
$a = str_replace("\\/", "/", json_encode($a));
var_dump($a);
// 其二 php版本>5.4
var_dump(json_encode($a,JSON_UNESCAPED_SLASHES));


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post