public static string StripHTML(string html)
        {
            try
            {
                System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                html = regex1.Replace(html, ""); //过滤<script></script>标记
                html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
                html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on事件
                html = regex4.Replace(html, ""); //过滤iframe
                html = regex5.Replace(html, ""); //过滤frameset
                html = regex6.Replace(html, ""); //过滤frameset
                html = regex7.Replace(html, ""); //过滤frameset
                html = regex8.Replace(html, ""); //过滤frameset
                html = html.Replace(" ", "");
                html = html.Replace("</strong>", "");
                html = html.Replace("<strong>", "");
                html = html.Replace("\r", "");
                html = html.Replace("\n", "");
                html = html.Replace("'", "");
                html = html.Replace("\"", "");
                html = html.Replace("\t", "");
                return html;
            }
            catch
            {
                //MessageBox.Show("Error");
                return html;
            }
        }

最新文章

  1. Linux--Tail命令
  2. Eclipse迁移到Android studio步骤如下:
  3. easyui tree onloadsuccess事件的心得
  4. 【BZOJ-1176&amp;2683】Mokia&amp;简单题 CDQ分治
  5. 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: Section 1 Estimating unknown parameters
  6. hdu5432 二分
  7. $parse/$eval和$observe/$watch如何区分
  8. Tarjan求极大强连通分量模板
  9. NAT ALG原理
  10. 面试题 ARC
  11. ProjectA: 多元非线性回归
  12. FSG报表打印报错,log文件显示java.sql.SQLException: No corresponding LOB data found
  13. cuda中模板的使用
  14. MacOS搭建本地服务器
  15. 关于PHP上传文件时配置 php.ini 中的 upload_tmp_dir
  16. 1、Nexus安装
  17. django学习,session与cookie
  18. 20190402Linux常用命令week1.1
  19. 30.Mysql常见问题和应用技巧
  20. JavaScript 频繁发射事件处理的优化 --- 函数节流/事件稀释

热门文章

  1. 2019.02.28 bzoj4199: [Noi2015]品酒大会(sam+线段树)
  2. java生成pdf文件 --- Table
  3. (PMP)第11章-----项目风险管理
  4. VUE 动态给对象增加属性,并触发视图更新。
  5. 去掉input[type=&quot;number&quot;]的默认样式
  6. 居于H5的多文件、大文件、多线程上传解决方案
  7. zookeeper学习day01
  8. MFC控件的颜色设置
  9. 你可能不知道的github语法——图标
  10. sublime text 3中安装ctags支持函数跳转,安装convertToUtf8支持中文步骤[工具篇]