#region =====过滤html标签 RemoveHTML(string html)=====
        /// <summary>
        /// 过滤html
        /// </summary>
        /// <param name="html">需要过滤的字符串</param>
        /// <returns>过滤html后的字符串</returns>
        public static string RemoveHTML(string html)
        {
            html = Regex.Replace(html, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"-->", "", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"<!--.*", "", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"&#(\d+);", "", RegexOptions.IgnoreCase);
            html = Regex.Replace(html, @"<img[^>]*>;", "", RegexOptions.IgnoreCase);
            html.Replace("<", "");
            html.Replace(">", "");
            html.Replace("\r\n", "");
            //html = HttpContext.Current.Server.HtmlEncode(html).Trim();
            //html = HttpContext.Current.Server.HtmlDecode(html).Trim();
            return html;
        }
        #endregion

转载于:https://www.cnblogs.com/elephant-wp/archive/2011/11/01/2231373.html

过滤html标签 RemoveHTML相关推荐

  1. python3 正则 去除 html标签、提取正文内容_Python通过正则表达式去除(过滤)HTML标签,提取文字...

    # -*- coding: utf-8-*- import re ##过滤HTML中的标签 #将HTML中标签等信息去掉 #@param htmlstr HTML字符串. def filter_tag ...

  2. jquery过滤HTML标签方法

    //过滤HTML标签 function removeHTMLTag(str) {str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tags ...

  3. php正则过滤html标签_空格_换行符的代码,php正则过滤html标签、空格、换行符的代码(附说明)_php技巧...

    $str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/ $str=p ...

  4. Java过滤HTML标签工具类

    过滤HTML标签能有效的放置XSS攻击. 封装: import org.slf4j.Logger; import org.slf4j.LoggerFactory;import org.springfr ...

  5. PHP中过滤常用标签的正则表达式

    $str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...

  6. python文本筛选html_Python使用正则表达式去除(过滤)HTML标签提取文字功能

    正则表达式是一个特殊的字符序列,可以帮助您使用模式中保留的专门语法来匹配或查找其他字符串或字符串集. 正则表达式在UNIX世界中被广泛使用. 下面给大家介绍下Python使用正则表达式去除(过滤)HT ...

  7. php 实体转html,PHP 转HTML标签为实体, 把实体html标签转为,过滤html标签 | 学步园...

    1.在开发由于我的需要千变万化.我们得根据需求做各种各样的事情.下面我我在开发中遇到的,HTML标签互转的,记录下来与君共享 实例: $str = preg_replace("//" ...

  8. php 正则过滤style,PHP 过滤常用标签的正则表达式

    $str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/ $str=p ...

  9. 过滤html标签的代码

    public   String html2Text(String inputString) {           String htmlStr  =  inputString;  // 含html标 ...

最新文章

  1. 通过ajax调用WebService服务
  2. git如何切换分支_拜托,不要再问我Git分支如何使用
  3. Python报错SyntaxError: (unicode error) ‘utf-8‘ codec can‘t decode byte 0xc5 in position 0: invalid
  4. 2-2hadoop概述
  5. Myeclipse8.5 反编译插件 jad 安装(转)
  6. XXX.C(261): error C100: unprintable character 0xA1/3 skipped
  7. 创建私服maven服务
  8. 21. 投票(poll)
  9. 对于火灾和火焰检测的初步学习
  10. ThinkPHP多语言包功能使用
  11. 信鸽 ios tag推送 php,信鸽推送(iOS)踩过的坑
  12. 数据从阿里云迁移到腾讯云
  13. 修复YYC松鼠短视频系统我的收藏页面 没有返回按钮的bug
  14. Python迎来30岁生日,先驱Pablo Galindo:没想到Python这么流行
  15. 作为一个准研究生,怎样才能在研究生阶段不虚度?
  16. 打开vivado的.xpr工程文件报错Cannot locate target loader
  17. 量子纠缠的机制是什么?一定要理解整体性概念
  18. 把Safari整个页面翻译成中文,,
  19. 在字符串中查找子字符串
  20. 产品经理的主要工作内容

热门文章

  1. JZOJ 5257. 小X的佛光
  2. 用python排教室_开学季,教你用Python画大学教室座位神分区图!网友直呼“中枪”...
  3. 在Linux系统下生产者消费者,生产者-消费者问题实现 (linux下C语言)
  4. oracle 分段函数,transcad概述强大的交通gis.pdf
  5. 2019年东莞特长生 散步
  6. 2017年9月2日普级组T1 正方形
  7. python获取动态数据采集仪代理_Python3爬虫技术文档(3)——动态页面数据采集,三,获取...
  8. java开发流程图_Java 详解 JVM 工作原理和流程
  9. hadoop jar包_快速搭建Hadoop-Hive-Zoopkeeper-Sqoop环境进入Sqoop学习环境
  10. yaml数组解析_yaml格式详解