下面简单介绍这两个函数的用法:
string addcslashes(string str,string charlist)
第1个参数str为待失物原始字符串
第2个参数charlist说明需要在原始串的哪些字符前加上字符 “\”。
string stripcslashes(string str)
去掉字符串中的“\”。
另外,使用addslashes函数也可直接针对“'”进行转义处理。
示例如下:
"; $new_sql = addcslashes($sql,"'"); echo $new_sql."
"; $new_sql_01 = stripcslashes($new_sql); echo $new_sql_01."
"; 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