php正则过滤html标签、空格、换行符的代码(附说明)

yipeiwu_com5年前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标签,如javAsCript:alert(

相关文章

PHP简单实现欧拉函数Euler功能示例

本文实例讲述了PHP简单实现欧拉函数Euler功能。分享给大家供大家参考,具体如下: 欧拉函数ph(n)的意思是所有小于n且与n互质的个数。 比如说ph(10) = 4{1,3,7,9与...

PHPCMS遭遇会员投稿审核无效的解决方法 原创

今天接到主编那边的反馈,说本站的会员投稿平台,后台无法审核文章了,赶紧看看吧 本来想偷个懒,去度娘那里搜搜,看有相同情况的解决方案没,结果大失所望,虽然也有几个类似的情况,要么没解决,要...

php微信公众平台配置接口开发程序

php微信公众平台配置接口开发程序

在阅读这篇文章之前你要做以下的准备: 1.注册一个订阅号(通过微信公众平台https://mp.weixin.qq.com/); 2.注册新浪云并实名认证http://sae.sina....

redis查看连接数及php模拟并发创建redis连接的方法

max_redis.php <?php set_time_limit (0); for($i=1;$i<=1050;$i++){ exec("nohup p...

Linux安装配置php环境的方法

本文实例讲述了Linux安装配置php环境的方法。分享给大家供大家参考,具体如下: 1.获取安装文件: http://www.php.net/downloads.php php-5.3....