Home >Backend Development >PHP Problem >How to remove slashes in characters in php
How to delete slashes in characters in php: first open the corresponding PHP code file; then remove the backslashes through "stripslashes($_POST['json']);" and finally perform json_decode.
The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer
PHP removes the backslash in the json string\ And remove the backslash before the double quotes
The json string passed to PHP through AJAX is sometimes escaped with a backslash "\", which needs to be removed first when processing by PHP backslash, and then json_decode.
$str = stripslashes($_POST['json']); $arr = json_decode($str,true);
PS: How to remove the backslash in front of the double quotes when grabbing json with php get
This is not a standard JSON format data, you can first Just replace \" with ".
Use the json_decode() system function to convert it into a json object. If you need to convert it into an array, just add the second parameter to true.
If the output is still NULL, it is because there is BOM header information.
The code is as follows:
$arr = json_decode(trim($json,chr(239).chr(187).chr(191)),true);
Just convert it.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to remove slashes in characters in php. For more information, please follow other related articles on the PHP Chinese website!