In PHP, there are two functions related to the escape of strings: addslashes and stripslashes.
Addslashes ($ string), which is used to add a backslash (\) before a specified predefined character to prepare a suitable string for the string stored in the database and the database query statement.
Note: by default, the magic_quotes_gpc command of PHP is on, and addslashes () is automatically run for all GET, POST, and COOKIE data (). Do not use addslashes () for strings that have been escaped by magic_quotes_gpc, because this causes double-layer escape. In this case, you can use the get_magic_quotes_gpc () function for detection.
Stripslashes ($ string) is the inverse function of addslashes (). It is used to delete the backslash added by the addslashes () function to restore the characters to be escaped. It is also called inverse meaning, it is mainly used to clear data retrieved from a database or HTML form.
Which characters will addslashes escape:
Single quotes (')
Double quotation marks (")
Backslash (\)
NULL
In addition, strings with single quotes as delimiters support two escape characters:
Single quotes (')
Backslash (\)
Strings with double quotation marks as delimiters support the following escape characters:
\ N line feed (LF or ASCII character 0x0A (10 ))
\ R press enter (CR or ASCII character 0x0D (13 ))
\ T horizontal tab (HT or ASCII character 0x09 (9 ))
\ Backslash
\ $ Dollar sign
\ "Double quotation marks
\ [0-7] {} The regular expression sequence matches a character represented by the octal symbol
\ X [0-9A-Fa-f] {} This regular expression matches a sequence of characters represented by a hexadecimal symbol
Articles you may be interested in
- Php string replacement function str_replace is faster than preg_replace
- Summary of String Functions in PHP
- Php performance optimization: Using isset () to determine the string length is faster than strlen ()
- Comparison and Analysis of string encoding functions escape, encodeURI, and encodeURIComponent in javascript
- Some powerful string processing functions forgotten by php
- Php string Filter Function
- Php's most precise String Length truncation Function
- PHP generates continuous numbers (letters) Array Function range () analysis, PHP lottery program function