PHP json string processing of special characters (single quotes, double quotation marks) _ PHP Tutorial

Source: Internet
Author: User
Tags php json
The PHPjson string is used to process special characters (single quotation marks, double quotation marks ). PHP json string processing of special characters (single quotation marks, double quotation marks) Preface: form forms use POST, GET, and other methods to submit data to the background, the background uses PHP to receive submitted data contains, (double quotation marks, PHP json string processing of special characters (single quotation marks, double quotation marks)
Form forms are submitted to the background using POST, GET, and other methods, and received by PHP in the background.

The submitted data contains "", "", "\" (double quotation marks, single quotation marks, and backslash), and the new PHP version (magic_quotes_gpc in php. when ini is set to ON, the addslashes () is automatically escaped. 5.3 discard, 5.4 remove, all need to use addslashes () for escape) all need to use addslashes () to add escape.

The data submitted from the form accepted by PHP must be escaped with stripcslashes (), escaped with addslashes (), and inserted into the database.

Use addslashes () to escape the data stored in the database. after the data is obtained, use stripcslashes () to escape the data and use json_encode () to convert the data to json format, use addslashes () to escape and return it to js for js processing.

Note: json_decode (string, true) converts the parsed data to an array in this way. if the value is not true, it is converted to an object. The default value is false.

Http://www.bkjia.com/PHPjc/1060169.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1060169.htmlTechArticlePHP json string special character processing (single quotes, double quotes ,, \ (double quotation marks ,...

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.