In PHP, The json_encode does not automatically escape the slash "/".
Preface
Recently, when I saved the crawling link to the mysql database, I found that when I saved the link using json_encode, it showed escape characters in the database, and I didn't need this escape character, it looks unclear and occupies storage space.
Then it is found that, by default, the json format conversion using json_encode will automatically escape the string containing the slash in the data, but sometimes we do not need to escape them. This article describes how to use json_encode without automatically escaping the slash.
For the following array $ a, there are two solutions:
$ A = array ('HTTP: // www.baidu.com ', 'HTTP: // www.baidu.com: // www.baidu.com ');
First, regular expression replacement:
$ A = str_replace ("\/", "/", json_encode ($ a); var_dump ($ );
Second, if the php version is 5.4 or later:
Var_dump (json_encode ($ a, JSON_UNESCAPED_SLASHES ));
Summary
The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.