zoukankan      html  css  js  c++  java
  • 去掉字符串中的html标签

     1 public static string removeHtml(string html) 
     2 {
     3 
     4     System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     5 
     6     System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     7 
     8     System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[sS]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     9 
    10     System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    11 
    12     System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    13 
    14     System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"<img[^>]+>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    15 
    16     System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    17 
    18     System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    19 
    20     System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    21 
    22     html = regex1.Replace(html, ""); //过滤<script></script>标记
    23 
    24     html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
    25 
    26     html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
    27 
    28     html = regex4.Replace(html, ""); //过滤iframe
    29 
    30     html = regex5.Replace(html, ""); //过滤frameset
    31 
    32     html = regex6.Replace(html, ""); //过滤frameset
    33 
    34     html = regex7.Replace(html, ""); //过滤frameset
    35 
    36     html = regex8.Replace(html, ""); //过滤frameset
    37 
    38     html = regex9.Replace(html, "");
    39 
    40     html = html.Replace(" ", "");
    41 
    42     html = html.Replace("</strong>", "");
    43 
    44     html = html.Replace("<strong>", "");
    45 
    46     html = cutBadStr(html);
    47 
    48     return html.ToUpper();
    49 
    50 }
    51 
    52 public static string removeHtmlHasPic(string html) 
    53 {
    54 
    55     System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    56 
    57     System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    58 
    59     System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[sS]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    60 
    61     System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    62 
    63     System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    64 
    65     System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    66 
    67     System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    68 
    69     System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    70 
    71     html = regex1.Replace(html, ""); //过滤<script></script>标记
    72 
    73     html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
    74 
    75     html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
    76 
    77     html = regex4.Replace(html, ""); //过滤iframe
    78 
    79     html = regex5.Replace(html, ""); //过滤frameset
    80 
    81     html = regex7.Replace(html, ""); //过滤frameset
    82 
    83     html = regex8.Replace(html, ""); //过滤frameset
    84 
    85     html = regex9.Replace(html, "");
    86 
    87     html = html.Replace(" ", "");
    88 
    89     html = html.Replace("</strong>", "");
    90 
    91     html = html.Replace("<strong>", "");
    92 
    93     html = cutBadStr(html);
    94 
    95     return html;
    96 
    97 }
  • 相关阅读:
    ubuntu 11.10(32位系统)下编译android源码
    12 个基于 Rails 框架开发的 CMS 系统
    36 个 CSS 框架推荐
    再来 10 个新鲜的 HTML5 教程
    汇编程序开发环境搭配(转)
    推荐:介绍一个UndoFramework
    细数 Windows 平台上的 NoSQL 数据库
    使用ShareKit一键分享到Facebook,Twitter等平台
    25个jQuery的编程小抄
    10款iOS高效开发必备的ObjectiveC类库
  • 原文地址:https://www.cnblogs.com/lanmoxiaozhu/p/3401806.html
Copyright © 2011-2022 走看看