//匹配去掉h5标签
private function pregH5($info){
//先去掉<p> </p> Dxt489
$info = str_replace("<p> </p>","",$info);
//找到class为.Dxt489{display:none}的位置
$pos = strpos($info,"{ display:none;");
if($pos>0){
$checkString = substr($info,$pos-7,"6");//获取class值
//去掉 class为 Dxt489的值
$info = preg_replace('/<div class=\"'.$checkString.'\".*?>.*?<\/div>/ism','',$info);
$info = preg_replace('/<p class=\"'.$checkString.'\".*?>.*?<\/p>/ism','',$info);
//去掉style
$info = preg_replace('/<p><style type=\"text\/css\".*?>.*?<\/style><\/p>/ism','',$info);
}
//去掉空格
$info = str_replace(" "," ",$info);
$info = str_replace(""",'"',$info);
$info = str_replace("“",'"',$info);
$info = str_replace("”",'"',$info);
$info = str_replace("…",'...',$info);
$info = str_replace("<",'(',$info);
$info = str_replace(">",')',$info);
$info = str_replace("下一篇:",'',$info);
$info = str_replace("相关阅读:",'',$info);
$info = str_replace("推荐阅读:",'',$info);
$info = str_replace("来源:",'',$info);
$info = preg_replace("/<p(.*?)>/","",$info);
//去掉a标签
$info = preg_replace("/<a(.*?)>.*?<\/a>/","",$info);
// $info = preg_replace("/\s/","",$info);
// $info = str_replace(" ","",$info);//去空白
$info = str_replace("\r\n","",$info);//去换行
$info = str_replace("\n","",$info);//去换行
$info = str_replace("<br />","\n",$info);
$info = explode("</p>",$info);
$new = array();
foreach ($info as $key => $value) {
$value = preg_replace('/<[^>]*>/','',$value);
$value = str_replace('由提供','',$value);
if($value){
$new[$key] = $value;
}
}
//去掉p标签
// $info = preg_replace('/<[^>]*>/','\n',$info);
//去掉空白等换行符
/*$info = preg_replace("/\s/","",$info);
$info = str_replace("\r\n","",$info);
$info = str_replace("\n","",$info);*/
return $new;
}
php正则去除文章页标签范例
最新推荐文章于 2022-06-09 11:05:02 发布