This article describes the Addslashes () and stripslashes () implementation string escape and restore usage in PHP. Share to everyone for your reference, specific as follows:
The addslashes () function in PHP returns a string that adds a backslash before the predefined characters.
Predefined characters are:
Single quotation mark (')
Double quotation mark (")
Back slash (\)
Null
the Stripslashes () function deletes the backslash that was added by the addslashes () function .
Examples of usage are as follows:
<?php
$str = "Select * from ' book ' Where Bookname= ' cloud-dwelling community '";
echo $str. " <br/>/output string $str
echo $astr =addslashes ($STR);//String escaping and outputting
echo "<br/>";
echo stripslashes ($ASTR);//Restore the escaped string
?>
The results of the operation are as follows:
SELECT * from ' book ' Where Bookname= ' cloud Communities '
select * from ' book ' Where bookname=\ ' yun-Habitat Community \ '
select * ' book ' whe Re bookname= ' cloud-dwelling community '
Add:
The difference between the addslashes () and the Addcslashes () function:
It's two very close. But using a different function, the addslashes () function returns a string that adds a backslash before the predefined character, and the Addcslashes () function returns a string that adds a backslash before the specified character, so addcslashes () The function needs to add additional parameters to describe the specific characters that need to be added to the backslash.
The difference and usage of the two can refer to the difference and comparison between the analytic PHP addslashes () and the Addcslashes () function.
I hope this article will help you with the PHP program design.