One, addslashes () function
The 1.addslashes () function is a backslash before the specified predetermined character. Syntax: Addslashes (str);
2. The parameter is a string
3. There are four types of predefined characters: Single quotation mark ('), double quotation mark ("), backslash (\), and null
4. For example:
<?php $str = "who ' s John Adams?"; echo $str. " This is not safe in a database query.<br/> ";//output: Who's John Adams? This is the not safe in a database query. echo addslashes ($STR). " This is safe in a database query. "; /output: who\ ' s John Adams? This is sage in a database query. >
12345678910
Second, addcslashes () function
The 1.addcslashes () function is to add a backslash before the specified character.
Syntax: Addcslashes (str,chararcters);
2. Medium parameter str is required, which specifies the string to be checked, while character is optional and specifies the range of characters or characters affected by addcslashes ().
3. Example 1:
<?php $str = "hello,my name is John Adams."; echo $str; Output: hello,my name is John adams.echo addcslashes ($str, ' m '); Output: hello,\my na\me is John ada\ms.echo addcslashes ($str, ' J '); Output: hello,my name is \john Adams ?>
123456789101112
Example 2,
<?php$str= "hello,my name is John Adams."; echo $str; Output: hello,my name is John adams.echo addcslashes ($str, ' A. Z '); Output: \hello,my name is \john \adams.echo addcslashes ($str, ' A. Z '); Output: h\e\l\l\o,\m\y \n\a\m\e \i\s j\o\h\n a\d\a\m\s.echo addcslashes ($str, ' A. h '); Output: H\ello,my n\am\e is Jo\hn a\d\ams.? >
1234567891011121314
Note: the Addcslashes () function is case-sensitive for the specified character or range of characters.
Add a backslash before the character "W":
<?php $str = addcslashes ("Hello world!", "W"); Echo ($STR);?>
Definition and usage
The Addcslashes () function returns a string that adds a backslash before the specified character.
Note: the Addcslashes () function is case-sensitive.
Note: Be careful when applying addcslashes () to 0 (NULL), R (carriage return), N (newline), T (page break), F (tab), and V (Vertical tab). In PHP, the \ r, \ n, \ t, \f, and \v are predefined escape sequences.
Grammar
Addcslashes (String,characters)
Parameter description
string is required. Specifies the string to be escaped.
Characters required. Specifies the character or range of characters to be escaped.
Technical details return value:
Returns the escaped string.
To add a backslash to a specific character in a string:
<?php$str = "Welcome to my humble homepage!"; echo $str. " <br> "; Echo addcslashes ($str, ' m ')." <br> "; Echo addcslashes ($str, ' H ')." <br> ";? >
Example 2
To add a backslash to a character in a range in a string:
<?php$str = "Welcome to my humble homepage!"; echo $str. " <br> "; Echo addcslashes ($str, ' A. Z '). " <br> "; Echo addcslashes ($str, ' A. Z '). " <br> "; Echo addcslashes ($str, ' A. G ');? >