Home >Backend Development >PHP Problem >How to remove slashes in php

How to remove slashes in php

藏色散人
藏色散人Original
2021-07-23 10:40:202456browse

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.

How to remove slashes in php

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!

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