关于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 ...
随机推荐
- FastJson的使用方法总结
本文参考:http://www.tuicool.com/articles/zUbQfa 还可参考:https://www.iflym.com/index.php/code/alibaba-fastjs ...
- ORACLE之表
本文章中的表在以后的例子中会用到. 首先有t_fn_person和t_fn_dept表. ) primary key not null, person_code ) not null, person_ ...
- C# 短信猫(SMS cat) 操作源码开发经验
我曾经开发的某项目需要使用短信猫模块,要求使用C#编程操作.能独立使用的动态链接库之一就是网上流传的sms.dll,但它的功能较少,不能满足需求,鉴于一时找不到合适的完整代码,我深入研究了短信协议,借 ...
- 配置SQL Server 2008 R2 Reporting Services
记录如何在本地配置SQL Server 2008 R2 Reporting Services,笔者环境为Windows 7 64位 + SQL Server 2008 R2 一.准备工作 其实准备工作 ...
- MySQL之控制台修改密码
进入控制台:use mysql Database changed update user set password=PASSWORD('设置的密码') where user='root'; flush ...
- Linux下用freetds连接mssql中文乱码的问题【参考1】
由于工作原因我们需要通过php访问我们以前的Sql Server 2005数据,所以就有了这篇文章的诞生.废话就少说了,做程序设计的最不喜欢兜圈子了.用简介步骤说明问题,往下看.系统: Linux ...
- centOS6.5x64简单的安装openfire
yum install java libldb.i686 mysql-server mysql-connector-java 创建数据库 create database openfire defaul ...
- 读书笔记-UIView与控件
1.UIView 在Objective-C中,NSObject是所有类的“根”类.同样,在UIKit框架中,也存在一个如此神奇的类UIView.从继承关系上看,UIView是所有视图的根. 1.1.U ...
- 直播开始:'云榨汁机'诞生记--聊聊JavaScript中的'业务建模'
闭包是JavaScript中的一个重要特性,在之前的博文中,我们说闭包是一个'看似简单,其实很有内涵'的特性.当我们用JavaScript来实现相对复杂的业务建模时,我们可以如何利用'闭包'这个特性呢 ...
- 从0开始学习react(二)
今天,开始学习第二节!!! 工欲善其事,必先利其器 react推荐我们使用webpack来打包文件,那么我们就用吧!(其实真心不想用啊) 至于好处网上写的天花乱坠的,大家自行解决啊... 这节主要就学 ...