zoukankan      html  css  js  c++  java
  • c# 过滤html

      public static string StripHTML(string html)
            {
                try
                {
                    System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[sS]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                    System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</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("
    ", "");
                    html = html.Replace("
    ", "");
                    html = html.Replace("'", "");
                    html = html.Replace(""", "");
                    html = html.Replace("	", "");
                    return html;
                }
                catch
                {
                    //MessageBox.Show("Error");
                    return html;
                }
            }
  • 相关阅读:
    区块链技术的应用场景
    区块链快速了解
    区块链工作汇报部分问题
    区块链Fabric 交易流程
    maven配置settings.xml【阿里云】
    Java常用工具类整理
    程序员职业思考:从大数据到人工智能再到区块链
    Python实现图像信息隐藏
    Python直接控制鼠标键盘
    Mac使用Clion配置OpenGL
  • 原文地址:https://www.cnblogs.com/feizianquan/p/9720751.html
Copyright © 2011-2022 走看看