Home > Backend Development > PHP Tutorial > PHP function stripslashes() that removes backslashes added by addslashes() function

PHP function stripslashes() that removes backslashes added by addslashes() function

黄舟
Release: 2023-03-17 06:28:01
Original
2136 people have browsed it

Example

Remove Backslash:

<?php
echo stripslashes("Who&#39;s Peter Griffin?");
?>
Copy after login

Definition and usage

stripslashes() function is deleted by addslashes () The backslash added by the function.

Tip: This function can be used to clean data retrieved from the database or from an HTML form.

Syntax

stripslashes(string)
Copy after login
ParametersDescription
string Required. Specifies the string to be checked

Technical details

Return value: Returns the string with backslashes stripped.
PHP version: 4+

##By default, the PHP command magic_quotes_gpc is on , automatically runs addslashes() on all GET, POST and COOKIE data. This is for database security. Some characters are unsafe to store directly in the database. They are: Single quote (')
Double quote (")
Backslash (\)
NULL
*** *************************************************** *************************************************** *******
addslashes() function adds a backslash before the specified predefined characters. These predefined characters are:
Single quote (')
Double quote (") ##. #Backslash(\)
NULL
************************************ *************************************************** ************************

Example of addslashes():


<?php
$str = "Who&#39;s John Adams?";
echo $str . " This is not safe in a database query.<br />";
echo addslashes($str) . " This is safe in a database query.";
?>
Copy after login

Output:


Who&#39;s John Adams? This is not safe in a database query.
Who\&#39;s John Adams? This is safe in a database query.
Copy after login

************************ *************************************************** ************************************

stripslashes() function is the reverse of addslashes() Action, that is: remove the backslashes added by the addslashes() function. **************************************************** *************************************************** *************
stripslashes() Example:


<?php
echo stripslashes("Who\&#39;s John Adams?");
?>
Copy after login

Output:


Who&#39;s John Adams?
Copy after login

The above is the detailed content of PHP function stripslashes() that removes backslashes added by addslashes() function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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