PHP removes backslash in JSON string and backslash _php instance before double quotation mark is removed

Source: Internet
Author: User
The JSON string that is passed to PHP via Ajax is sometimes added with a backslash "\" to escape, and PHP needs to be stripped of the backslash before Json_decode.

 

ps:php get fetch JSON how to remove backslash before double quotation mark

This is not the standard JSON format data, you can first "replace".

Then use the Json_decode () system function to convert it to a JSON object, if you want to convert to an array plus the second argument is true.

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

Copy the Code code as follows:
$arr = Json_decode (Trim ($json, Chr (239). chr (187). Chr (191)), true);

Conversion.

This article is all finished, and I hope you will be helpful in using PHP to remove the backslash in the JSON string and to remove the backslash before the double quotation mark.

  • 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.