: This article mainly introduces examples of character string conversion and restoration usage of addslashes and stripslashes in PHP. For more information about PHP tutorials, see. The example in this article describes how to convert and restore strings using addslashes () and stripslashes () in PHP. We will share this with you for your reference. The details are as follows:
In PHP, the addslashes () function returns a string that adds a backslash before a predefined character.
The predefined characters are:
Single quotes (')
Double quotation marks (")
Backslash (\)
NULL
The stripslashes () function deletes the backslash added by the addslashes () function.
Example:
<? Php $ str = "select * from 'book' where bookname = ''"; echo $ str ."
"; // Output string $ str echo $ astr = addslashes ($ str); // escape string and output echo"
"; Echo stripslashes ($ astr); // restore the escape string?>
The running result is as follows:
Select * from 'book' where bookname = 'site 'select * from 'book' where bookname = \ 'site \ 'select * from 'book' where bookname = 'site'
Supplement:
Differences between addslashes () and addcslashes () functions:
These two functions are very similar in writing but use different functions. the addslashes () function returns a string that adds a backslash before a predefined character, while the addcslashes () function () the function returns a string that adds a backslash before a specified character. Therefore, the addcslashes () function needs to add additional parameters to indicate that the specific character of the backslash needs to be added.
For details about the differences and usage of the two, refer to the article "differences and comparison between parsing php addslashes () and addcslashes () functions".
I hope this article will help you with PHP programming.
The above introduces the examples of character string conversion and restoration usage of addslashes and stripslashes in PHP, including some content, and hope to help friends who are interested in PHP tutorials.