PHP removes the backslash from the json string and the backslash before the double quotation marks. json double quotation marks _ PHP Tutorial

Source: Internet
Author: User
PHP removes the backslash in the json string and the backslash before the double quotation marks. json double quotation marks. PHP removes the backslash in the json string and the backslash before the double quotation marks. json double quotation marks are sometimes escaped by adding a backslash (") to the json string uploaded to PHP through AJAX, during PHP processing, PHP needs to remove the backslash \ in the json string and the backslash before the double quotation marks. json double quotation marks

The json string uploaded to PHP through AJAX is sometimes escaped by adding a backslash "\". during PHP processing, you need to remove the backslash and then use json_decode.

$ Str = stripslashes ($ _ POST ['json']); $ arr = json_decode ($ str, true );

PS: php get how to remove the backslash before double quotation marks when capturing json

If your data is not in the standard JSON format, you can replace \ "with" first.

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

If the output is still NULL, the BOM header information exists,

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

Convert.

This article describes all the content, hoping to help you remove the backslash \ in the json string and the backslash before double quotation marks in PHP.

Sometimes the backslash (\) is added to the json string uploaded to PHP through AJAX. it is required for PHP processing...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.