沉浸式阅读
Beta
转载

php正则过滤html标签、空格、换行符的代码

     订阅 PHP     2022-08-28     www.php.cn    网络转载    696    0    1    1    2022-08-28
学习要点:请用代码测试

代码如下

$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正则过滤html标签、空格、换行符的代码

本文链接: https://www.mbkfw.com/course/1114.html (转载时请注明来源链接)

本文说明: 本文来源于网络转载,有问题请发送至: 邮箱/kf@dtmuban.com 进行修改或删除

特别鸣谢: 如果您觉得本文对您有帮助,请给我们一个小小的赞,收藏本文更利于反复学习哦!

 
本文标签: #过滤
destoon程序前端开发标签生成器

下班PC阅读不方便?

手机也可以随时学习开发

微信关注公众号“商企云服”
"模板开发网前端开发教学"
每日干货技术分享
 
0

圈友点评

文明上网理性发言,请遵守网络评论服务协议

小编推荐



色彩
×

《客户实名在线注册登记》售后一直都在!

关注

微信
关注

微信扫一扫
不同的环境体验

幸运大转盘,好礼等您拿

模板开发网公众号

模板开发网微信小程序

代授权

程序
授权

黑小二

联系
客服

很高兴为您服务
尊敬的用户,欢迎您咨询,我们为新用户准备了优惠好礼。咨询客服

联系客服:

在线QQ: 290948585

客服电话: 18605917465

E_mail邮箱: kf@dtmuban.com

微信公众号: 商企云服

微信小程序: 模板开发

QQ客服 微信客服DT授权代办 在线交谈 智能小云

工作时间:

周一至周五: 09:00 - 18:00

APP下载

安卓
APK

模板开发网安卓版APP

反馈

我要
反馈