PHP过滤各种HTML标签的表达式,值得收藏
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
$str=preg_replace("/<\s*img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i", " ", $str); //过滤img标签$str=preg_replace("/\s+/", " ", $str); //过滤多余回车$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)$str=preg_replace("/<\!--.*?-->/si","",$str); //注释$str=preg_replace("/<(\!.*?)>/si","",$str); //过滤DOCTYPE$str=preg_replace("/<(\/?html.*?)>/si","",$str); //过滤html标签$str=preg_replace("/<(\/?head.*?)>/si","",$str); //过滤head标签$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //过滤meta标签$str=preg_replace("/<(\/?body.*?)>/si","",$str); //过滤body标签$str=preg_replace("/<(\/?link.*?)>/si","",$str); //过滤link标签$str=preg_replace("/<(\/?form.*?)>/si","",$str); //过滤form标签$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //过滤applet标签$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //过滤applet标签$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //过滤style标签$str=preg_replace("/<(\/?style.*?)>/si","",$str); //过滤style标签$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //过滤title标签$str=preg_replace("/<(\/?title.*?)>/si","",$str); //过滤title标签$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //过滤object标签$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //过滤object标签$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //过滤noframes标签$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //过滤noframes标签$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //过滤frame标签$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //过滤frame标签$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //过滤script标签$str=preg_replace("/<(\/?script.*?)>/si","",$str); //过滤script标签$str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签$str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签$str=preg_replace("/on([a-z]+)\s*=/si","On\\1=",$str); //过滤script标签$str=preg_replace("/&#/si","&#",$str); //过滤script标签 |
如果仅仅是过滤一整篇篇html文档,
比如说head这样的整篇文档中所有的html标签,则可以用 php的 strip_tags()函数来脱掉所有的html或php标签。
需要注意的是:strip_tags()函数是不怎么验证标签的完整性的,也就说如果缺少一个或者其他的标签,则很有可能导致有更多的内容被脱掉。
PHP过滤各种HTML标签的表达式,值得收藏的更多相关文章
- JSTL标签,EL表达式,OGNL表达式,struts2标签 汇总
一下纯属个人总结摘抄,总结一起方便查看,解决疑问,有遗漏或错误,还请指出. 1,JSTL标签总结: a).JSTL标签有什么用? JSTL是由JCP(Java Commu ...
- PHP通用的XSS攻击过滤函数,Discuz系统中 防止XSS漏洞攻击,过滤HTML危险标签属性的PHP函数
XSS攻击在最近很是流行,往往在某段代码里一不小心就会被人放上XSS攻击的代码,看到国外有人写上了函数,咱也偷偷懒,悄悄的贴上来... 原文如下: The goal of this function ...
- 前端学习——css基础知识,选择器与html模板、值得收藏的html标签
一.css需要的html(采用html5标准) DTD,文档类型声明: <!Doctype html> 文本编码声明: <meta charset="utf-8" ...
- 过滤字符串html标签方法
过滤字符串html标签方法,如果输入的过滤标签为“*”,那么给字符串加上p标签 public static string noTagHtml(string str, string tagname) { ...
- 正则过滤html的标签
$('#Text').find('br').remove();//移除br标签 let content = $('#smsText').html().replace(/ /g, ' ').replac ...
- div+css样式命名规则,值得收藏
div+css样式命名规则,值得收藏 头:header 内容:content/container 尾:footer 导航:nav 侧栏:sidebar 栏目:column 页面外围控制整体布局宽度:w ...
- [转帖]超详细的PostgreSQL体系结构总结,值得收藏
超详细的PostgreSQL体系结构总结,值得收藏 https://www.toutiao.com/i6715390855772897800/ 原创 波波说运维 2019-07-26 00:03:00 ...
- [转帖]分享Oracle的四道经典面试题,值得收藏
分享Oracle的四道经典面试题,值得收藏 原创 波波说运维 2019-07-20 00:02:00 https://www.toutiao.com/i6713901660919300621/ 概述 ...
- 最值得收藏的Bootstrap资源网站
如果你正在寻找Bootstrap图标,那今天的推荐对你而言绝对非常重要!在这篇内容中,我们把这套框架上的免费字体图 标做了个整合(当然,以后还会不断的更新).正如你所知,图标字体在一个web网页设计拥 ...
随机推荐
- 51Nod:独木舟问题(贪心)
n个人,已知每个人体重,独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人.显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟? 输入 第一行包含两个正 ...
- mvc之URL篇
一.根据路由系统生成友好的URL ActionLink(this HtmlHelper htmlHelper, string linkText, string actionName); 会根据当前的路 ...
- 强连通分量【k 算法、t 算法】
连通分量就是一个各个顶点能互相达到的图 无向图的连通分量选取任意一个顶点使用DFS遍历即可,遍历完所有顶点所需的DFS的次数就是连通分量的数量 有向图的强连通分量由于是有向的[从A点开始DFS能访问到 ...
- encode decode enumerate
format的用法 print(format('aa','>20')) print(format('aa','<20')) print(format('aa','^20')) 打印结果如下 ...
- leetcode:Palindrome Number【Python版】
一次AC 题目要求中有空间限制,因此没有采用字符串由量变向中间逐个对比的方法,而是采用计算翻转之后的数字与x是否相等的方法: class Solution: # @return a boolean d ...
- FastAdmin 自己做的插件 SQL 有一个表没有生成成功
群里有群友问: 给插件建的install.sql 里有三个表,为啥会出现安装成功后没有错误提示,只生成了两个表的情况..这可能会是什么...原因 第一感觉和 FastAdmin 没有关系. 没生成表, ...
- Centos7安装killall,fuser, killall,pstree和pstree.x11
centos7精简安装后,使用中发现没有killall命令. 经查找,可以通过以下命令解决: yum -y install psmisc 简单介绍一下 psmisc : Psmisc软件包包含三个帮助 ...
- mysql复制表结构create table as和like的区别
对于MySQL的复制相同表结构方法,有create table as 和create table like 两种,区别是什么呢? create table t2 as select * from t1 ...
- 简单的爬虫例子——爬取豆瓣Top250的电影的排名、名字、评分、评论数
爬取思路: url从网页上把代码搞下来bytes decode ---> utf-8 网页内容就是我的待匹配的字符串ret = re.findall(正则,待匹配的字符串), ret 是所有匹配 ...
- nginx信号量
nginx信号说明相关说明 信号名称 作用 TERM,INT 快速关闭 QUIT 从容关闭 HUP 重新加载配置,用新的配置开始新的工作进程,从容关闭旧的工作进程 USR1 重新打开日志文件 USR2 ...