In PHP, there are two functions related to string escaping, they are addslashes and stripslashes.
addslashes($string), adds a backslash () before the specified predefined characters, used to prepare appropriate strings for strings stored in the database and database query statements.
Note: By default, the PHP directive magic_quotes_gpc is on, automatically running addslashes() on 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 function get_magic_quotes_gpc() to detect it.
stripslashes($string) is the inverse function of addslashes(). It is used to delete the backslashes added by the addslashes() function to restore the escaped characters. It is also called anti-escaping. It is mainly used to clean up the database. Or the data retrieved from the HTML form.
So which characters will be escaped by addslashes, as follows:
Single quote (')
Double quotes (")
backslash ()
NULL
In addition, strings with single quotes as delimiters support two escape characters:
Single quote (')
backslash ()
A string delimited by double quotes, supports the following escapes:
n Line feed (LF or ASCII character 0x0A (10))
r carriage return (CR or ASCII character 0x0D (13))
t horizontal tab character (HT or ASCII character 0x09 (9))
\ backslash
$ dollar sign
"Double quotes
[0-7]{1,3} This regular expression sequence matches a character represented in octal notation
x[0-9A-Fa-f]{1,2} This regular expression sequence matches a character represented in hexadecimal notation