-
- //向字符串中的特定字符添加反斜杠
- $str = "Hello, my name is John Adams.";
- echo $str;
- echo addcslashes($str,'m');
- echo addcslashes($str,'J');
- ?>
-
复制代码
输出:
-
- //向字符串中的预定义字符添加反斜杠
- $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.";
- ?>
复制代码
输出:
Who's John Adams? This is not safe in a database query.
Who's John Adams? This is safe in a database query.
对于函数addslashes()和addclashes(),都有对应的去除反斜杠的方法,分别为:stripcslashes函数和stripslashes函数。有兴趣的朋友,也可以研究下。
|