PHP中addcslashes与stripcslashes函数用法分析,stripcslashes_PHP教程

WBOY
Release: 2016-07-12 09:01:22
Original
920 people have browsed it

PHP中addcslashes与stripcslashes函数用法分析,stripcslashes

本文实例分析了PHP中addcslashes与stripcslashes函数用法。分享给大家供大家参考,具体如下:

在写一个网站的英文版时,写完后填加英文资料,我随便填写时一点问题没有,但每当填加指定的内容时却填加不上,也不报错,我查看了数据库,发现这个字段用的是“TEXT”数据数型,我以为是内容过长的原因,于是我把数据类型改成了“longtext”,但提交时发现还是出现同样的问题。下面我们给大家介绍一下addcslashes函数吧!

后来请教同事,同事发现在是英文中带标点“'”的原因,MySQL执行到此处后自动认为语句结束,所以才填加不上。既然找出来了问题那就得找出对应的解决方法,那就是在文本内容中的“'”前全部加上转义字符“\”,正好PHP中提供了自动在字符串中加入或去除转义字符的函数addcslashes和stripcslashes,于是加上测试后,果然问题解决!由此可见,我平日写程序时不够严禁,总是会忽略这样那样的细节问题,如果被HACKER发现这些问题加一利用,网站基本就OVER了,所以大家一定要引以为戒,不要和我犯同样的错误哦。

下面简单介绍这两个函数的用法:

string addcslashes(string str,string charlist)

第1个参数str为待失物原始字符串

第2个参数charlist说明需要在原始串的哪些字符前加上字符 “\”。

string stripcslashes(string str)

去掉字符串中的“\”。

另外,使用addslashes函数也可直接针对“'”进行转义处理。

示例如下:

<&#63;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);
&#63;>

Copy after login

运行结果如下:

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

Copy after login

希望本文所述对大家PHP程序设计有所帮助。

您可能感兴趣的文章:

  • PHP中addslashes()和stripslashes()实现字符串转义和还原用法实例
  • php中addslashes函数与sql防注入
  • PHP中使用addslashes函数转义的安全性原理分析
  • PHP关于htmlspecialchars、strip_tags、addslashes的解释
  • PHP函数addslashes和mysql_real_escape_string的区别
  • php stripslashes和addslashes的区别
  • 解析php addslashes()与addclashes()函数的区别和比较
  • php daddslashes()和 saddslashes()有哪些区别分析
  • php addslashes及其他清除空格的方法是不安全的
  • php addslashes和mysql_real_escape_string
  • php addslashes 函数详细分析说明

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1089582.htmlTechArticlePHP中addcslashes与stripcslashes函数用法分析,stripcslashes 本文实例分析了PHP中addcslashes与stripcslashes函数用法。分享给大家供大家参考,具体如下...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!