网络编程 
首页 > 网络编程 > 浏览文章

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

(编辑:jimmy 日期: 2024/10/10 浏览:3 次 )

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

$str=preg_replace("/\s+/", " ", $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)
$str=preg_replace("/<\!–.*","",$str); //注释
$str=preg_replace("/<(\!.*","",$str); //过滤DOCTYPE
$str=preg_replace("/<(\/","",$str); //过滤html标签
$str=preg_replace("/<(\/","",$str); //过滤head标签
$str=preg_replace("/<(\/","",$str); //过滤meta标签
$str=preg_replace("/<(\/","",$str); //过滤body标签
$str=preg_replace("/<(\/","",$str); //过滤link标签
$str=preg_replace("/<(\/","",$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签
$str=preg_replace("/<(applet.*","",$str); //过滤applet标签
$str=preg_replace("/<(\/","",$str); //过滤applet标签
$str=preg_replace("/<(style.*","",$str); //过滤style标签
$str=preg_replace("/<(\/","",$str); //过滤style标签
$str=preg_replace("/<(title.*","",$str); //过滤title标签
$str=preg_replace("/<(\/","",$str); //过滤title标签
$str=preg_replace("/<(object.*","",$str); //过滤object标签
$str=preg_replace("/<(\/","",$str); //过滤object标签
$str=preg_replace("/<(noframes.*","",$str); //过滤noframes标签
$str=preg_replace("/<(\/","",$str); //过滤noframes标签
$str=preg_replace("/<(i","",$str); //过滤frame标签
$str=preg_replace("/<(\/","",$str); //过滤frame标签
$str=preg_replace("/<(script.*","",$str); //过滤script标签
$str=preg_replace("/<(\/","",$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标签

上一篇:js 正则表达式学习笔记之匹配字符串
下一篇:js 玩转正则表达式之语法高亮
一句话新闻
高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。