php去掉html标签函数代码

发布时间:2020-05-17编辑:脚本学堂
分享一个去除html标签的php函数,用于删除代码中的html标签,起到安全过滤的作用,有需要的朋友参考下。

例子,php删除html标签的函数。

代码:
 

复制代码 代码示例:
<?php
function noHTML($content)
{
  $content = preg_replace("/<a[^>]*>/i",'', $content);  
  $content = preg_replace("/</a>/i", '', $content);   
  $content = preg_replace("/<div[^>]*>/i",'', $content);  
  $content = preg_replace("/</div>/i",'', $content);
  $content = preg_replace("/<font[^>]*>/i",'', $content);  
  $content = preg_replace("/</font>/i",'', $content);
  $content = preg_replace("/<p[^>]*>/i",'', $content);  
  $content = preg_replace("/</p>/i",'', $content);
  $content = preg_replace("/<span[^>]*>/i",'', $content);  
  $content = preg_replace("/</span>/i",'', $content);
  $content = preg_replace("/<?xml[^>]*>/i",'', $content);
  $content = preg_replace("/</?xml>/i",'', $content);
  $content = preg_replace("/<o:p[^>]*>/i",'', $content);
  $content = preg_replace("/</o:p>/i",'', $content);
  $content = preg_replace("/<u[^>]*>/i",'', $content);
  $content = preg_replace("/</u>/i",'', $content);
  $content = preg_replace("/<b[^>]*>/i",'', $content);
  $content = preg_replace("/</b>/i",'', $content);
  $content = preg_replace("/<meta[^>]*>/i",'', $content);
       $content = preg_replace("/</meta>/i",'', $content);
  $content = preg_replace("/<!--[^>]*-->/i",'', $content);//注释内容 
  $content = preg_replace("/<p[^>]*-->/i",'', $content);//注释内容      
  $content = preg_replace("/style=.+?['|"]/i",'',$content);//去除样式  
  $content = preg_replace("/class=.+?['|"]/i",'',$content);//去除样式  
  $content = preg_replace("/id=.+?['|"]/i",'',$content);//去除样式     
  $content = preg_replace("/lang=.+?['|"]/i",'',$content);//去除样式      
  $content = preg_replace("/width=.+?['|"]/i",'',$content);//去除样式   
  $content = preg_replace("/height=.+?['|"]/i",'',$content);//去除样式   
  $content = preg_replace("/border=.+?['|"]/i",'',$content);//去除样式   
  $content = preg_replace("/face=.+?['|"]/i",'',$content);//去除样式
  $content = preg_replace("/face=.+?['|"]/",'',$content);
  $content = preg_replace("/face=.+?['|"]/",'',$content);
  $content=str_replace( "&nbsp;","",$content);
  return $content;
}

>>> 您可能感兴趣的文章:
PHP删除HTMl标签的代码
php 判断字符串是否包含html标签
提取html标签的php代码示例
php提取HTML标签的方法举例
php去除HTML标签的二种方法
php 去除多余的HTML标签
php正则 查找html中包含id属性的html标签
php用strip_tags完整去除所有html标签的实例分享
php删除html标签的三种方法分享
php删除html标签及字符串中html标签的代码
php删除字符串中html标签的函数
提取html标签的php代码
php正则过滤html标签、空格、换行符等的代码示例
修复未正常关闭的HTML标签(支持嵌套和就近闭合)的代码
php去除html标签获得输入纯文本文档strip_tags
php使HTML标签自动补全闭合函数的代码
php实现html标签自动补全的代码