Examples in this article describe the use of addslashes () and stripslashes () in PHP for string escaping and restoration. Share to everyone for your reference, as follows:
The addslashes () function in PHP returns a string that adds a backslash before a predefined character.
The predefined characters are:
Single quotation mark (')
Double quotation marks (")
Back slash (\)
Null
the Stripslashes () function deletes a backslash added by the addslashes () function .
The usage examples are as follows:
<?php $str = "Select * from ' book ' where Bookname= ' the site '"; echo $str. "
";//output String $str echo $astr =addslashes ($STR);//string escape and Output echo"
"; echo stripslashes ($ASTR);//Will escape string restore?>
The results of the operation are as follows:
SELECT * from ' book ' where Bookname= ' this station ' select * from the ' book ' where bookname=\ ' this station \ ' select * from ' book ' where Bookname= ' this station '
Add:
Addslashes () differs from the Addcslashes () function:
This is two very similar. 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 that describe the specific characters that need to be added with backslashes.
The two specific differences and usage can refer to the relevant articles of this site "parsing PHP addslashes () and addcslashes () functions of the difference and comparison"
I hope this article is helpful to you in PHP programming.
The above describes the PHP addslashes and stripslashes implementation of the string escape and restore usages, including the contents of the content, I hope the PHP tutorial interested in a friend helpful.