Home > Backend Development > PHP Tutorial > PHP removes backslashes in json strings and removes backslashes before double quotes, json double quotes_PHP tutorial

PHP removes backslashes in json strings and removes backslashes before double quotes, json double quotes_PHP tutorial

WBOY
Release: 2016-07-12 09:07:54
Original
1245 people have browsed it

PHP removes the backslash in the json string and removes the backslash before the double quote. The json double quote

The json string passed to PHP through AJAX is sometimes added Use backslash "" to escape. When processing with PHP, you need to remove the backslash first and then json_decode.

$str = stripslashes($_POST['json']); 
$arr = json_decode($str,true); 
Copy after login

PS: How to remove the backslash in front of double quotes when grabbing json with php get

Your data in JSON format is not standard. You can replace "with" first.

Use the json_decode() system function to convert it into a json object. If you need to convert it into an array, just add the second parameter to true.

If the output is still NULL, it is due to the existence of BOM header information,

Copy code The code is as follows:
$arr = json_decode(trim($json,chr(239).chr(187).chr(191)),true);

Just convert.

The entire content of this article has been introduced. I hope it will be helpful to you in using PHP to remove backslashes in json strings and remove backslashes before double quotes.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1058158.htmlTechArticlePHP removes the backslash in the json string and removes the backslash before the double quotation mark. The json double quotation mark passes The json string passed from AJAX to PHP is sometimes escaped with a backslash "", which needs to be processed by PHP...
Related labels:
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