关于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-5686 Problem B(斐波那契数列)
题目链接: Problem B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu 4719 动态规划
思路:dp[i]表示到第i个点为结尾能获得的最大值,那么dp[i]=h[i]*h[i]+dp[i-x]-h[i-x];(i-l<=x<=i);那么我们可以转换下,以dp[i]-h[i]为新 ...
- 数据库知识(主要基于Oracle,Sql可参考)
1.关于Union的知识 select 11 from dual union select 11 from dual 和 select 11 from dual union all select 11 ...
- 苹果宣布首批HomeKit智能家居设备将在6月上市
凤凰科技讯 北京时间5月15日消息,据<华尔街日报>网络版报道,苹果周四宣布,首批支持其HomeKit平台的智能家居设备将在下月上市.这一消息的发布也驳斥了关于该苹果家庭自动化软件平台将推 ...
- hdu 1222 Wolf and Rabbit
Problem Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbi ...
- 解决discuz与jquery不兼容问题——下拉列表不能用(Uncaught TypeError: Cannot set property 'position' of undefined)
问题描述: 最近学着用discuz来模仿一个门户网站,里面要把导航条做出滑动效果,要用到jquery,将要用到jquery引用到header.htm中,如下图所示: 但是由于discuz采用php以及 ...
- 集合框架学习之排序Comparable&Comoarator
1.内置引用数据类型比较(常用) 1.1 Comparable 1.整数.小数Integer Float Double 直接比较基本数据类型的大小 2.字符:比较的Unicode码只差 3.字符串: ...
- 应该始终以PreparedStatement代替Statement
在JDBC应用中,如果你已经是稍有水平开发者,你就应该始终以PreparedStatement代替Statement.也就是说,在任何时候都不要使用Statement 一.代码的可读性和可维护性.虽然 ...
- 洛谷 P1209 修理牛棚== Codevs 2079 修理牛棚
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题目描述 Description 在一个夜黑风高,下着暴风雨的夜晚,farmer John的牛棚的屋顶.门被吹 ...
- While readingiphone真机无法显示图片,而模拟器可以正常显示
可能,很多开发IOS程序的遇到过在模拟器里,加载图片都是正常的,但是在真机里就会出现图片资源不能加载的问题. 其中一种原因是,在Simulator里面,例如:图片资源名称为:a.PNG,在代码你里,你 ...