PHP中过滤常用标签的正则表达式

作者:mdxy-dxy 时间:2024-05-03 15:35:43 

我们常常会用到PHP过滤一些标签的功能,比如过滤链接标签、过滤script标签等等,下面就介绍一下PHP过滤常用标签的正则表达式代码:


$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标签
标签:PHP,过滤标签
0
投稿

猜你喜欢

  • MySQL索引下推详细

    2024-01-18 10:01:07
  • Python如何读写CSV文件

    2023-03-23 08:41:13
  • MySQL优化之大字段longtext、text所生产的问题

    2024-01-28 11:37:43
  • 在Python中使用__slots__方法的详细教程

    2022-10-30 09:46:10
  • Python配置文件yaml的用法详解

    2023-07-04 21:02:56
  • 有关wxpython pyqt内存占用问题分析

    2022-11-02 11:37:14
  • 你会使用python爬虫抓取弹幕吗

    2021-04-28 03:06:50
  • ASP.NET教程第一讲 ASP.NET简介

    2007-08-07 11:50:00
  • 只用40行Python代码就能写出pdf转word小工具

    2021-11-03 18:02:00
  • python 用opencv实现霍夫线变换

    2021-09-14 20:18:25
  • python实现电子书翻页小程序

    2022-11-16 11:10:29
  • HTML 标签是否匹配检测代码

    2010-03-17 20:50:00
  • python遍历字符串中每一个字符的4种方式

    2022-12-21 07:33:03
  • 15款最佳jQuery LightBox插件

    2010-09-25 12:41:00
  • Pandas 按索引合并数据集的方法

    2023-06-01 13:35:10
  • pytorch 常用函数 max ,eq说明

    2023-06-25 11:09:21
  • 复制SqlServer数据库的方法

    2024-01-26 22:46:26
  • Oracle字符集修改查看方法

    2009-11-05 21:45:00
  • Django实现支付宝付款和微信支付的示例代码

    2021-01-31 10:16:29
  • PHP 中文处理技巧

    2024-05-11 09:45:09
  • asp之家 网络编程 m.aspxhome.com