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

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

黄舟
黄舟Original
2017-11-04 10:38:412014browse

Example

Remove Backslash:

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

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)
Parameters Description
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.";
?>

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.

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

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?");
?>

Output:


Who&#39;s John Adams?

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!

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