-
- //Add backslashes to specific characters in the string
- $str = "Hello, my name is John Adams.";
- echo $str;
- echo addcslashes($str, 'm');
- echo addcslashes($str,'J');
- ?>
-
Copy code
output:
-
- //Add backslash to predefined characters in string
- $str = "Who's John Adams?";
- echo $str . " This is not safe in a database query .
";
- echo addslashes($str) . " This is safe in a database query.";
- ?>
Copy code
output:
Who's John Adams? This is not safe in a database query.
Who's John Adams? This is safe in a database query.
For the functions addslashes() and addclashes(), there are corresponding methods for removing backslashes, namely: stripcslashes function and stripslashes function. Friends who are interested can also study it.
|