How to make json_encode not automatically escape the slash "/" in PHP

Recently, when I saved the link crawled by the crawler to the mysql database, I found that when I saved the link using json_encode, the escaped characters were displayed in the database. I didn't need this escape, it looked unclear and took up storage. space.

Later, it was found that using json_encode to convert the array to json format by default will automatically escape the strings containing slashes in the data, but we often do not need to escape them sometimes. This article talks about how to use json_encode without escaping slashes automatically.

For the following array $a, there are two solutions:

$a = array (
);
First, regular replacement:
$a = str_replace("\\/", "/", json_encode($a));

var_dump($a);

Second, if the php version is 5.4 and above:

var_dump(json_encode($a,JSON_UNESCAPED_SLASHES));

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324484608&siteId=291194637