php stripslashes() addslashes() 解析

stripslashes() 函数删除由 addslashes() 函数添加的反斜杠。

实例:

<?php
$str = "Is your name O\'reilly?";

// Outputs: Is your name O'reilly?
echo stripslashes($str);
?>

 

输出:

Who's John Adams?

 

 

 

addslashes() 函数在指定的预定义字符前添加反斜杠。

 

这些预定义字符是:

 

  • 单引号 (')
  • 双引号 (")
  • 反斜杠 (\)

实例:

<?php
$str = "Who's John Adams?";
echo $str . " This is not safe in a database query.<br />";
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.

 

 

posted @ 2014-05-13 23:20  timelesszhuang  阅读(379)  评论(0编辑  收藏  举报