php method to remove slashes: first create a PHP sample file; then remove the backslashes in the string through the "stripslashes($_POST['json']);" method; finally encode it through json_decode That’s it.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to remove slashes in php?
PHP removes the backslash in the json string\
The json string passed to PHP through AJAX is sometimes escaped with a backslash "\", PHP During processing, you need to remove the backslashes first;
and then use the json_decode.
$str = stripslashes($_POST['json']); $arr = json_decode($str,true);
stripslashes() function to delete the backslashes added by the addslashes() function.
Tip: This function can be used to clean data retrieved from the database or from an HTML form.
json_decode is a PHP built-in function added after php5.2.0. Its function is to encode strings in JSON format.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove slashes in php. For more information, please follow other related articles on the PHP Chinese website!