Home >Backend Development >PHP Tutorial >PHP json string processing of special characters (single quotes, double quotes)_PHP tutorial

PHP json string processing of special characters (single quotes, double quotes)_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:07:361228browse

PHP json string processing of special characters (single quotes, double quotes)

Preface: The form submits data to the background using POST, GET, etc., and the background uses PHP to receive it.
The submitted data contains """, "'", "" (double quotes, single quotes, backslashes), which will be automatically escaped by addslashes() in the new version of PHP (magic_quotes_gpc when php.ini is set to ON). Deprecated in 5.3 and removed in 5.4, you need to use addslashes() to escape) You need to use addslashes() to add escapes yourself
.
The data submitted by the form accepted by PHP needs to be escaped first with stripcslashes() and then with addslashes() before being inserted into the database.
Use addslashes() to escape the data stored in the database. After taking it out, the same method applies: you need to use stripcslashes() to escape first, then use json_encode() to convert the required data into json format, and then use addslashes( ) is returned to js after escaping and let js process it.
Note: json_decode(string,true) uses this method to directly convert the data to be parsed into an array. If it is not true later, it will be converted into object form. Default is false

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1060169.htmlTechArticlePHP json string processing of special characters (single quotes, double quotes) Preface: form forms use POST, GET, etc. method to submit data to the background, and the background uses PHP to receive the submitted data containing,, (double quotes,...
Statement:
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