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;
                }
            }
  • 相关阅读:
    校园网络(tarjan)
    消息扩散(强连通分量)
    上帝造题的七分钟(树桩数组乱搞)
    数颜色 / 维护队列(带修莫队)
    Luogu5155 [USACO18DEC]Balance Beam
    分数规划小结
    Luogu3177 [HAOI2015]树上染色
    Luogu4402 机械排序
    Luogu3201 [HNOI2009]梦幻布丁
    Luogu3380 二逼平衡树
  • 原文地址:https://www.cnblogs.com/feizianquan/p/9720751.html
Copyright © 2011-2022 走看看