1. Remove backslashes through the "stripslashes($_POST['json']);" method. 2. Use "json_decode" to decode the string in JSON format. The json string passed to PHP via AJAX is sometimes escaped with a backslash "\". When processing it in PHP, you need to remove the backslash first and then json_decode it. $str = stripslashes($_POST['json']);$arr = json_decode($str,true); stripslashes() function: Removes backslashes added by the addslashes() function. json_decode: Decodes a string in JSON format. Knowledge point expansion: How to prevent json_encode from automatically escaping slashes "/" in PHP Recently, when I saved the links crawled by the crawler into the mysql database, I found that when I saved the links using json_encode, the escape characters were displayed in the database. I don’t need this escape, it looks unclear and takes up storage space. Later, I found that under the default circumstances, when using json_encode to convert the array to json format, the strings containing slashes in the data will be automatically escaped, but sometimes we don't need to escape them. This article explains how to use json_encode without automatically escaping slashes. For the following array $a, there are two solutions: $a = array( '//www.jb51.net, '//www.jb51.net, '//www.jb51.net, '//www.jb51.net, '//www.jb51.net ); 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)); This is the end of this article about the example of how to remove backslashes in json in php. For more information about how to remove backslashes in json in php, please search for previous articles on 123WORDPRESS.COM or continue to browse the related articles below. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: calc() to achieve full screen background fixed width content
>>: Web front-end development CSS related team collaboration
I am going to review Java these two days, so I wr...
To set the line spacing of <p></p>, us...
<br />Previous Web Design Tutorial: Web Desi...
1. Use the SELECT clause to query multiple tables...
Database stored procedures DROP PROCEDURE IF EXIS...
First, take a look at Alibaba Cloud's officia...
This article uses examples to describe how to bac...
jQuery form validation example / including userna...
Shorthand properties are used to assign values ...
In a project, you often need to use environment v...
Nginx can use the limit_req_zone directive of the...
Table of contents Preface NULL in MySQL 2 NULL oc...
1. Multi-header table code Copy code The code is a...
Table of contents 1. Component 2. keep-alive 2.1 ...
In MySQL, database garbled characters can general...