欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

PHP清除html格式的代码

程序员文章站 2022-03-21 20:08:24
...
$descclear = str_replace("\r","",$descclear);//过滤换行
$descclear = str_replace("\n","",$descclear);//过滤换行
$descclear = str_replace("\t","",$descclear);//过滤换行
$descclear = str_replace("\r\n","",$descclear);//过滤换行
$descclear = preg_replace("/\s+/", " ", $descclear);//过滤多余回车
$descclear = preg_replace("//si","",$descclear); //过滤html注释
$descclear = preg_replace("//si","",$descclear); //过滤DOCTYPE
$descclear = preg_replace("//si","",$descclear); //过滤html标签
$descclear = preg_replace("//si","",$descclear); //过滤head标签
$descclear = preg_replace("//si","",$descclear); //过滤meta标签
$descclear = preg_replace("//si","",$descclear); //过滤body标签
$descclear = preg_replace("//si","",$descclear); //过滤link标签
$descclear = preg_replace("//si","",$descclear); //过滤form标签
$descclear = preg_replace("/cookie/si","COOKIE",$descclear); //过滤COOKIE标签
$descclear = preg_replace("/(.*?)/si","",$descclear); //过滤applet标签
$descclear = preg_replace("//si","",$descclear); //过滤applet标签
$descclear = preg_replace("/(.*?)/si","",$descclear); //过滤style标签
$descclear = preg_replace("//si","",$descclear); //过滤style标签
$descclear = preg_replace("/(.*?)/si","",$descclear); //过滤title标签
$descclear = preg_replace("//si","",$descclear); //过滤title标签
$descclear = preg_replace("/(.*?)/si","",$descclear); //过滤object标签
$descclear = preg_replace("//si","",$descclear); //过滤object标签
$descclear = preg_replace("/(.*?)/si","",$descclear); //过滤noframes标签
$descclear = preg_replace("//si","",$descclear); //过滤noframes标签
$descclear = preg_replace("/(.*?)/si","",$descclear); //过滤frame标签
$descclear = preg_replace("//si","",$descclear); //过滤frame标签
$descclear = preg_replace("/(.*?)/si","",$descclear); //过滤script标签
$descclear = preg_replace("//si","",$descclear); //过滤script标签
$descclear = preg_replace("/javascript/si","Javascript",$descclear); //过滤script标签
$descclear = preg_replace("/vbscript/si","Vbscript",$descclear); //过滤script标签
$descclear = preg_replace("/on([a-z]+)\s*=/si","On\\1=",$descclear); //过滤script标签
$descclear = preg_replace("//si","&#",$descclear); //过滤script标签,如javAsCript:alert();
//使用正则替换
$pat = "/]*?)>/isU";
$descclear = preg_replace($pat,"",$descclear);