关于htmlentities 、htmlspecialchars、addslashes的使用
1、html_entity_decode():把html实体转换为字符。
Eg:$str = "just atest & 'learn to use '";
echo html_entity_decode($str);
echo "<br />";
echo html_entity_decode($str,ENT_QUOTES);
echo "<br />";
echo html_entity_decode($str,ENT_NOQUOTES);
输出如下:
just a test & 'learn to use '
just a test & 'learn to use '
just a test & 'learn to use '
2、htmlentities():把字符转换为html实体。
Eg:$str = "just a test & 'learn to use'";
echo htmlentities($str,ENT_COMPAT);
echo "<br/>";
echo htmlentities($str, ENT_QUOTES);
echo "<br/>";
echo htmlentities($str, ENT_NOQUOTES);
输出如下:
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
查看源代码如下:
just a test & 'learn to use'<br />
just a test & 'learn to use'<br />
just a test & 'learn to use'
3、addslashes():在指定的预定义字符前添加反斜杠
预定义字符包括:单引号(‘),双引号(“),反斜杠(\),NULL
默认情况下,PHP指令 magic_quotes_gpc 为 on,对所有的GET、POST 和COOKIE 数据自动运行 addslashes()。不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。遇到这种情况时可以使用函数get_magic_quotes_gpc() 进行检测。
Eg:$str3="\ just a ' \" test";
echoaddslashes($str3);
输出:
\\ just a \' \" test
4、stripslashes():删除由addslashes函数添加的反斜杠
Eg:$str4="\\ just a \'\" test";
echo stripslashes($str4);
输出:
just a ' " test
5、 htmlspecialchars():把一些预定义的字符转换为html实体。
预定义字符包括:
& (和号) 成为&
" (双引号) 成为"
' (单引号) 成为'
< (小于) 成为<
> (大于) 成为>
Eg:$str5 = "just atest & 'learn to use'";
echo htmlspecialchars($str5, ENT_COMPAT);
echo "<br/>";
echo htmlspecialchars($str5, ENT_QUOTES);
echo "<br/>";
echo htmlspecialchars($str5, ENT_NOQUOTES);
输出:
just a test & 'learn to use'
just a test & 'learn to use'
just a test & 'learn to use'
查看源代码: just a test & 'learn to use'<br />
just a test & 'learn to use'<br />
just a test & 'learn to use'
6、 htmlspecialchars_decode():把一些预定义的html实体转换为字符。
会被解码的html实体包括:& 成为 &(和号)
" 成为 " (双引号)
' 成为 ' (单引号)
< 成为 < (小于)
> 成为 > (大于)
Eg:$str6 = "just atest & 'learn to use'";
echo htmlspecialchars_decode($str6);
echo "<br />";
echo htmlspecialchars_decode($str6, ENT_QUOTES);
echo "<br />";
echo htmlspecialchars_decode($str6, ENT_NOQUOTES);
输出:
just a test & 'learn to use '
just a test & 'learn to use '
just a test & 'learn to use '
查看源代码:
just a test & 'learn to use '<br />
just a test & 'learn to use '<br />
just a test & 'learn to use '
至此,我想大家对着几个函数的基本试用应经明白了吧。
关于htmlentities 、htmlspecialchars、addslashes的使用的更多相关文章
- php的strip_tags,htmlspecialchars,htmlentities,stripslashes,addslashes解释
php函数蛮多的,要完整的每个函数都理解深刻是个挺有挑战性的事情. strip_tags,htmlspecialchars,htmlentities,stripslashes,addslashes这几 ...
- htmlentities,html_entity_decode,addslashes
PHP htmlspecialchars_decode() 函数 PHP htmlspecialchars() 函数 PHP html_entity_decode() 函数 PHP中混淆的三组函数总结 ...
- strip_tags,htmlspecialchars,htmlentities,stripslashes,addslashes学习小结
一.strip_tags 从字符串中去除 HTML 和 PHP 标记 string strip_tags ( string $str [, string $allowable_tags ] ) str ...
- htmlentities、addslashes 、htmlspecialchars的使用
1.html_entity_decode():把html实体转换为字符. Eg:$str = "just atest & 'learn to use '";echo htm ...
- 浅谈htmlentities 、htmlspecialchars、addslashes的使用方法
html_entity_decode():把html实体转换为字符. $str = "just atest & 'learn to use '"; echo html_en ...
- php htmlentities和htmlspecialchars 的区别
很多人都以为htmlentities跟htmlspecialchars的功能是一样的,都是格式化html代码的,我以前也曾这么认为,但是今天我发现并不是这样的. The translations ...
- PHP对表单提交特殊字符的过滤和处理
PHP关于表单提交特殊字符的处理方法做个汇总,主要涉及htmlspecialchars/addslashes/stripslashes/strip_tags/mysql_real_escape_str ...
- PHP安全编程
转自:http://www.nowamagic.net/librarys/veda/detail/2076 1.关闭register_globals,以提高安全性 2.在部署环境,不要让不相关的人 ...
- 防XXS和SQL注入
对网站发动XSS攻击的方式有很多种,仅仅使用php的一些内置过滤函数是对付不了的,即使你将filter_var,mysql_real_escape_string,htmlentities,htmlsp ...
- GeSHi Documentation
GeSHi Documentation Version 1.0.8.11 Authors: © 2004 - 2007 Nigel McNie © 2007 - 2012 Benny Baumann ...
随机推荐
- hdu 4421 Bit Magic
[题意] 这个函数是给A求B的,现在给你B,问你是否能有A的解存在. [2-SAT解法] 对于每个A[i]的每一位运行2-sat算法,只要跑到强连通就可以结束,应为只要判断是否有解,后面拓扑求解就不需 ...
- vijos P1037搭建双塔
P1037搭建双塔 Accepted 标签:动态规划 背包 描述 2001年9月11日,一场突发的灾难将纽约世界贸易中心大厦夷为平地,Mr. F曾亲眼目睹了这次灾难.为了纪念“9?11”事件, ...
- 手机app(功能)测试重点
在手机客户端进行查看的测试重点:1.“点击加载更多”的分页处理技术,是否有重复的数据,数据显示是否完整,到达最后一页后是否还有数据进行显示2.数据的排序方式2.界面跳转是否正确3.出现异常情况是否有提 ...
- 当“逻辑”与“UE”冲突时
如上图. 权限系统有三个对象:用户.角色和组. 角色代表自定义的权限集合. "组"你可以理解为"文件夹"."部门"等名词. 一个用户可以拥有 ...
- Part 1 What is SSMS?
note that,SSMS is a client tool and not the server by itself,it is a developer machines connects to ...
- 发布ASP.NET网站到IIS
1. 在Web项目中点击发布网站,如图1所示 图1 2. 选择要发布的路径——>“确定”,如果项目显示发布成功就可以了.如图2所示 图2 3. 打 ...
- 位图文件格式及linux下C语言来操作位图文件
说到图片,位图(Bitmap)当然是最简单的,它是Windows显示图片的基本格式,其文件扩展名为*.BMP.由于没有经过任何的压缩,故BMP图片往往很大.在Windows下,任何格式的图片文件都要转 ...
- 8个WEB前端创意HTML5动画应用精选
和十几年前相比,现在的网页加入了很多动画元素,从之前的Flash到现在的HTML5,动画样式越来越丰富,动画制作也越来越便捷.本文精选了几款非常富有创意的HTML5动画应用,欣赏一下吧. 1.HTML ...
- PCB常用度量衡单位
1英尺=12英寸 1英寸inch=1000密尔mil 1mil=25.4um 1mil=1000uin (mil密耳有时也成英丝) 1um=40uin(有些公司称微英寸为麦,其实是微英寸) 1OZ=2 ...
- 处理jquery版本之间冲突
处理jquery版本之间冲突 前端开发们都知道jquery版本有好多,之间冲突很纠结.比如我刚来这公司的时候,后端的哥们用的是jQuery 1.3.2,我了个去,那哥们好久没更新了.我写的效果插件都是 ...