实例
删除 world! 前面的反斜杠:
<?php
echo stripslashes("hello world!");
?>
定义和用法
stripcslashes() 函数删除由 addcslashes() 函数添加的反斜杠。
提示:该函数可用于清理从数据库中或者从 html 表单中取回的数据。
语法
stripcslashes(string)
参数 描述
string 必需。规定要检查的字符串。
技术细节
返回值: 返回非转义的字符串。
php 版本: 4+
另外,使用addslashes函数也可直接针对“'”进行转义处理。
示例如下:
<?php
$sql = "update book set bookname='let's go' where bookid=1";
echo $sql."<br/>";
$new_sql = addcslashes($sql,"'");
echo $new_sql."<br/>";
$new_sql_01 = stripcslashes($new_sql);
echo $new_sql_01."<br/>";
echo addslashes($sql);
?>
运行结果如下:
update book set bookname='let's go' where bookid=1
update book set bookname=\'let\'s go\' where bookid=1
update book set bookname='let's go' where bookid=1
update book set bookname=\'let\'s go\' where bookid=1
以上就是php删除由addcslashes()函数添加的反斜杠函数stripcslashes()的详细内容。