本篇文章给大家分享的是有关addcslashes与stripcslashes函数怎么在PHP中使用,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
下面简单介绍这两个函数的用法:
string addcslashes(string str,string charlist)
第1个参数str为待失物原始字符串
第2个参数charlist说明需要在原始串的哪些字符前加上字符 “\”。
string stripcslashes(string str)
去掉字符串中的“\”。
另外,使用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
以上就是addcslashes与stripcslashes函数怎么在PHP中使用,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注天达云行业资讯频道。