Home > Article > Backend Development > PHP returns the function addslashes() that adds a backslash before a predefined character
Example
Add a backslash before each double quote ("):
<?php $str = addslashes('What does "yolo" mean?'); echo($str); ?>
Definition and usage
addslashes() function returns the predefined characters Strings preceded by a backslash:
Single quotation mark (')
Double quotation mark (")
Backslash. Bar (\)
NULL
Tip: This function can be used to prepare appropriate strings for strings stored in the database and database query statements.
Note: By default, the PHP instruction magic_quotes_gpc is on, automatically running addslashes() for all GET, POST and COOKIE data. Do not use addslashes() on strings that have been escaped by magic_quotes_gpc, as this will result in double escaping. When encountering this situation, you can
use the functionget_magic_quotes_gpc() for detection. Syntax
addslashes(string)
Description | |
Required. Specifies the string to be escaped. |
Returns the escaped string. | |
4+ |
The above is the detailed content of PHP returns the function addslashes() that adds a backslash before a predefined character. For more information, please follow other related articles on the PHP Chinese website!