Definition and usage
The Addslashes () function adds a backslash before the specified predefined character.
These predefined characters are:
Single quotation mark (') Double quotation mark (") backslash (\) NULL syntax
Addslashes (String)
Hints and Notes
Tip: This function can be used to prepare the appropriate string for strings stored in the database and for database query statements.
Note: By default, PHP instruction MAGIC_QUOTES_GPC is on, and automatically runs Addslashes () for all GET, POST, and COOKIE data. Do not use Addslashes () for strings that have been MAGIC_QUOTES_GPC escaped, because this results in double-layer escaping. You can use the function GET_MAGIC_QUOTES_GPC () to detect this situation.
Example
In this case, we're going to add a backslash to the predefined characters in the string:
"; Echo addslashes ($STR)." This is safe in a database query. ";? > Output:
Who ' s John Adams? This is the not safe in a database query. Who\ ' s John Adams? This is safe in a database query.