How to remove slashes in php

藏色散人
Release: 2023-03-11 19:12:02
Original
2389 people have browsed it

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);
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!