当前位置:Gxlcms > PHP教程 > php中addslashes()和addclashes()函数的区别分析

php中addslashes()和addclashes()函数的区别分析

时间:2021-07-01 10:21:17 帮助过:3人阅读

  1. //向字符串中的特定字符添加反斜杠
  2. $str = "Hello, my name is John Adams.";
  3. echo $str;
  4. echo addcslashes($str,'m');
  5. echo addcslashes($str,'J');
  6. ?>

输出:

  1. //向字符串中的预定义字符添加反斜杠
  2. $str = "Who's John Adams?";
  3. echo $str . " This is not safe in a database query.
    ";
  4. echo addslashes($str) . " This is safe in a database query.";
  5. ?>

输出:

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函数。有兴趣的朋友,也可以研究下。

人气教程排行