如何把在线编辑器提交到数据库中的数据,在读取的时候把html<>标签都去掉,只要纯文本?

解决方案 »

  1.   

    你用InnerHtml显示,自然就是纯文本了,Html都自动转化为样式
      

  2.   

    /// 选择去除哪种代码                                                                  
    /// SCRIPT    去除所有客户端脚本javascipt,vbscript,jscript,js,vbs,event,...; 
    /// TABLE   去除表格元素; 
    /// CLASS   去除样式类class=""; 
    /// STYLE     去除样式style=""; 
    /// XML   去除XML; 
    /// NAMESPACE 去除命名空间; 
    /// FONT      去除字体; 
    /// MARQUEE   去除滚动字幕; 
    /// OBJECT   去除对象; 
    /// </param> 
    /// <returns></returns>
    public static string HtmlDecodeFilter(string Html,string Filter)
    {
    switch(Filter)
    {
    case "SCRIPT": // 去除所有客户端脚本javascipt,vbscript,jscript,js,vbs,event,...
    Html = Regex.Replace(Html,@"</?script[^>]*>", "", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"(javascript|jscript|vbscript|vbs):", "$1:", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"on(mouse|exit|error|click|key)", "<I>on$1</I>", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"&#", "<I>&#</I>", RegexOptions.IgnoreCase);
    break;
    case "TABLE": // 去除表格<table><tr><td><th>
    Html = Regex.Replace(Html,@"</?table[^>]*>", "", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"</?tbody[^>]*>", "", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"</?tr[^>]*>", "", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"</?th[^>]*>", "", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"</?td[^>]*>", "",RegexOptions.IgnoreCase);
    break;
    case "CLASS": // 去除样式类class=""
    Html = Regex.Replace(Html,@"(<[^>]+) class=[^ |^>]*([^>]*>)", "$1 $2", RegexOptions.IgnoreCase) ;
    break;
    case "STYLE": // 去除样式style=""
    Html = Regex.Replace(Html,"(?<[^>]+) style=[\"|'][^\"]*[\"|']([^>]*>)", "$1 $2", RegexOptions.IgnoreCase);
    break;
    case "XML": // 去除XML<?xml>
    Html = Regex.Replace(Html,@"<\\?xml[^>]*>", "", RegexOptions.IgnoreCase);
    break;
    case "NAMESPACE": // 去除命名空间<o:p></o:p>
    Html = Regex.Replace(Html,@"<\/?[a-z]+:[^>]*>", "",RegexOptions.IgnoreCase);
    break;
    case "FONT": // 去除字体<font></font>
    Html = Regex.Replace(Html,@"</?font[^>]*>", "", RegexOptions.IgnoreCase);
    break;
    case "MARQUEE": // 去除字幕<marquee></marquee>
    Html = Regex.Replace(Html,@"</?marquee[^>]*>", "", RegexOptions.IgnoreCase);
    break;
    case "OBJECT": // 去除对象<object><param><embed></object>
    Html = Regex.Replace(Html,@"</?object[^>]*>", "", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"</?param[^>]*>", "", RegexOptions.IgnoreCase);
    Html = Regex.Replace(Html,@"</?embed[^>]*>", "", RegexOptions.IgnoreCase);
    break;
    default:
    break;
    }
    return Html;
    }
      

  3.   

    TO: JzeroBiao(先知)    能否说详细一点!?
      

  4.   

    用正则替换。
    例:System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]*</script *>System.Text.RegularExpressions.RegexOptions.IgnoreCase);htmlCode = regex1.Replace(html, string.Empty);//其他的依此加入。
      

  5.   

    哦可以的...
    把它的值放在一个标签里,然后取标签的InnerText...
      

  6.   

    晕..其实不用放在标签里..取它的InnerText就行了..