php正则过滤html标签、空格、换行符的代码(附说明)
时间:2023-07-22 07:58:01
$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标签,如javAsCript:alert(
标签:正则,过滤html
0
投稿
猜你喜欢
MySQL实现清空分区表单个分区数据
2024-01-14 03:45:34
sql查询表中根据某列排序的任意行语句
2024-01-13 02:13:18
关于vscode 默认添加python项目的源目录路径到执行环境的问题
2022-01-29 06:00:34
python热力图实现简单方法
2023-10-28 06:14:41
python 合并多个excel中同名的sheet
2023-06-06 08:34:27
mysql误删root用户恢复方法
2024-01-22 01:44:18
认清区别CSS的类class和id
2007-10-08 12:02:00
jupyter-lab设置自启动及远程连接开发环境
2023-08-29 09:11:39
Python爬虫破解登陆哔哩哔哩的方法
2021-03-28 14:17:40
DataFrame 数据合并实现(merge,join,concat)
2022-03-28 04:24:02
Python Matplotlib绘制多子图详解
2021-01-11 11:27:05
Python 从相对路径下import的方法
2023-06-15 03:16:10
分享10个程序员常用的的代码文本编辑器
2023-03-04 00:53:16
Python日志:自定义输出字段 json格式输出方式
2022-08-20 01:27:19
idea+git合并分支解决冲突及详解步骤
2022-10-07 00:18:27
自动备份Oracle数据库
2024-01-16 01:16:55
Python-split()函数实例用法讲解
2023-12-12 07:13:20
macOS M1(AppleSilicon) 安装TensorFlow环境
2022-05-26 04:03:34
使用Eclipse如何开发python脚本
2022-06-25 12:41:39
Python字节码与程序执行过程详解
2022-01-25 04:45:24