zoukankan      html  css  js  c++  java
  • 清除文本中Html的标签

    /// <summary>  
    /// 清除文本中Html的标签  
    /// </summary>  
    /// <param name="Content"></param>  
    /// <returns></returns>  
    protected string ClearHtml(string Content)
    {
    	Content = ReplaceHtml("&#[^>]*;", "", Content);
    	Content = ReplaceHtml("</?marquee[^>]*>", "", Content);
    	Content = ReplaceHtml("</?object[^>]*>", "", Content);
    	Content = ReplaceHtml("</?param[^>]*>", "", Content);
    	Content = ReplaceHtml("</?embed[^>]*>", "", Content);
    	Content = ReplaceHtml("</?table[^>]*>", "", Content);
    	Content = ReplaceHtml(" ", "", Content);
    	Content = ReplaceHtml("</?tr[^>]*>", "", Content);
    	Content = ReplaceHtml("</?th[^>]*>", "", Content);
    	Content = ReplaceHtml("</?p[^>]*>", "", Content);
    	Content = ReplaceHtml("</?a[^>]*>", "", Content);
    	Content = ReplaceHtml("</?img[^>]*>", "", Content);
    	Content = ReplaceHtml("</?tbody[^>]*>", "", Content);
    	Content = ReplaceHtml("</?li[^>]*>", "", Content);
    	Content = ReplaceHtml("</?span[^>]*>", "", Content);
    	Content = ReplaceHtml("</?div[^>]*>", "", Content);
    	Content = ReplaceHtml("</?th[^>]*>", "", Content);
    	Content = ReplaceHtml("</?td[^>]*>", "", Content);
    	Content = ReplaceHtml("</?script[^>]*>", "", Content);
    	Content = ReplaceHtml("(javascript|jscript|vbscript|vbs):", "", Content);
    	Content = ReplaceHtml("on(mouse|exit|error|click|key)", "", Content);
    	Content = ReplaceHtml("<\?xml[^>]*>", "", Content);
    	Content = ReplaceHtml("<\/?[a-z]+:[^>]*>", "", Content);
    	Content = ReplaceHtml("</?font[^>]*>", "", Content);
    	Content = ReplaceHtml("</?b[^>]*>", "", Content);
    	Content = ReplaceHtml("</?u[^>]*>", "", Content);
    	Content = ReplaceHtml("</?i[^>]*>", "", Content);
    	Content = ReplaceHtml("</?strong[^>]*>", "", Content);
    	string clearHtml = Content;
    	return clearHtml;
    }
    /// <summary>  
    /// 清除文本中的Html标签  
    /// </summary>  
    /// <param name="patrn">要替换的标签正则表达式</param>  
    /// <param name="strRep">替换为的内容</param>  
    /// <param name="content">要替换的内容</param>  
    /// <returns></returns>  
    private string ReplaceHtml(string patrn, string strRep, string content)
    {
    	if (string.IsNullOrEmpty(content))
    	{
    		content = "";
    	}
    	Regex rgEx = new Regex(patrn, RegexOptions.IgnoreCase);
    	string strTxt = rgEx.Replace(content, strRep);
    	return strTxt;
    }
    	              
    
  • 相关阅读:
    WebService-.Net:添加web引用和添加服务引用有什么区别?
    袁氏-人物-科学家:袁隆平(首届国家最高科学技术奖得主、杂交水稻之父)
    术语-BLOB:BLOB
    术语-PM:PM/项目管理 百科
    计算机:SAP (服务访问点(Service Accessing point))
    服务器-Web服务器-Tengine:Tengine 百科
    笔记-Git:Git 笔记
    DB-MDM:MDM/主数据管理 百科
    DB-MD:MD/主数据
    [Ext JS 4] 实战之 带week(星期)的日期选择控件
  • 原文地址:https://www.cnblogs.com/TTonly/p/12082927.html
Copyright © 2011-2022 走看看