In PHP, addslashes () and stripslashes () are used for string conversion and restoration. Examples of character string conversion and restoration using addslashes () and stripslashes () in PHP. Examples of this article describe the use of escape characters in PHP: addslashes () and stripslashes () implement string conversion and PHP addslashes () and stripslashes () to implement string conversion and restoration. use escape characters
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 = 'House of help'"; 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 = ' 'select * from 'book' where bookname = \' \ 'select * from 'book' where bookname = '''
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.
Articles you may be interested in:
- Php addslashes functions and SQL anti-injection
- Analysis on the security principle of escaping using the addslashes function in PHP
- PHP explanation of htmlspecialchars, strip_tags, and addslashes
- Differences between PHP functions addslashes and mysql_real_escape_string
- Differences between php stripslashes and addslashes
- Differences and comparison between php addslashes () and addclashes () functions
- What are the differences between php daddslashes () and saddslashes ()?
- Php addslashes and other methods for clearing spaces are insecure.
- Php addslashes and mysql_real_escape_string
- Php addslashes function detailed analysis description
- Analysis of addcslashes and stripcslashes functions in PHP
Conversion () and stripslashes () implement string conversion and restoration usage examples. the usage of escape characters in this article describes the use of addslashes () and stripslashes () in PHP to realize string conversion and conversion...