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

Source: Internet
Author: User
This article describes how to remove backslashes from json strings in PHP and the backslashes before double quotation marks in PHP. For more information, see

This article describes how to remove the backslash \ from the json string in PHP and the backslash before double quotation marks in PHP. For more information, see

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.

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.