实例

删除 "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()的详细内容,更多请关注Work网其它相关文章!

09-18 06:50