各位大侠,帮帮忙啊,怎么去掉 html标签中有带有“>”的标签啊?

解决方案 »

  1.   

    public string NoHtml(string src)
            {
                Regex htmlReg = new Regex(@"<[^>]+>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                Regex htmlSpaceReg = new Regex("\\&nbsp\\;", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                Regex spaceReg = new Regex("\\s{2,}|\\ \\;", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                Regex styleReg = new Regex(@"<style(.*?)</style>", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                Regex scriptReg = new Regex(@"<script(.*?)</script>", RegexOptions.Compiled | RegexOptions.IgnoreCase);            src = styleReg.Replace(src, string.Empty);
                src = scriptReg.Replace(src, string.Empty);
                src = htmlReg.Replace(src, string.Empty);
                src = htmlSpaceReg.Replace(src, " ");
                src = spaceReg.Replace(src, " ");
                return src.Trim();
            }
      

  2.   

     /// <summary>
        /// 过滤HTML字符 和 UBB代码
        /// </summary>
        public static string NoCode(string str)
        {
            if (str == null || str.Length == 0) return "";
            str = Regex.Replace(str, @"\<(?<x>[^\>]*)\>", @"", RegexOptions.IgnoreCase);
            str = Regex.Replace(str, @"\[(?<x>[^\]]*)\]", @"", RegexOptions.IgnoreCase);
            str = str.Replace("&nbsp;", " ");
            str = str.Replace("&gt;", ">");
            str = str.Replace("&lt;", "<");
            str = str.Replace("\n", "   ");
            str = str.Replace("\r", "");
            str = str.Replace("'", "");
            return str;
        }
      

  3.   

    直接使用 replace不可以吗???
      

  4.   

    不行啊,就像这一个img标签<IMG border=undefined alt="" src="http://localhost/TonyInformationManagementSystem/Information//image/12257534377600.jpg" onload="javascript:if(this.width>740)this.width=740">有一个大于号,所以它的那个标签没有清理完整
      

  5.   

    JQuery应该能解决这个问题。至于怎么解决有待商榷
      

  6.   

    Regex.Replace(str,@"<[^> ]+>",""); 过滤所有html
      

  7.   

    replace
    htmlencode();
    htmldecode();
    utilityencode();
    tobase64()
    from base64()
      

  8.   

    最后成这德性了,二敏 咋办? 740)this.width=740"> 
      

  9.   

     r = new Regex(@"(\[b\])([ \t]*?)(\[\/b\])",RegexOptions.IgnoreCase);
       for (m = r.Match(s); m.Success; m = m.NextMatch()) 
       {
        s= s.Replace(m.Groups[0].ToString(),"<B>" + m.Groups[2].ToString() + "</B>");
       }   r = new Regex(@"(\[i\])([ \t]*?)(\[\/i\])",RegexOptions.IgnoreCase);
       for (m = r.Match(s); m.Success; m = m.NextMatch()) 
       {
        s= s.Replace(m.Groups[0].ToString(),"<I>" + m.Groups[2].ToString() + "</I>");
       }   r = new Regex(@"(\[U\])([ \t]*?)(\[\/U\])",RegexOptions.IgnoreCase);
       for (m = r.Match(s); m.Success; m = m.NextMatch()) 
       {
        s= s.Replace(m.Groups[0].ToString(),"<U>" + m.Groups[2].ToString() + "</U>");
       }
      

  10.   

    晕,你啊...我回复的时候怎么没看到是你...无语..html是你自己写的还是直接拷贝的?