zoukankan      html  css  js  c++  java
  • Asp.Net 清除Html标签

    /// <summary>
    /// 清除Html标签
    /// </summary>
    /// <param name="content"></param>
    /// <returns></returns>
    protected string ClearHtmlTag(string htmlString)
    {
    //删除脚本
    htmlString = Regex.Replace(htmlString, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
    //删除Html
    htmlString = Regex.Replace(htmlString, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"([ ])[s]+", "", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"-->", "", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"<!--.*", "", RegexOptions.IgnoreCase);

    htmlString = Regex.Replace(htmlString, @"&(quot|#34);", """, RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(iexcl|#161);", "xa1", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(cent|#162);", "xa2", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(pound|#163);", "xa3", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(copy|#169);", "xa9", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(ldquo);", "“", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&(rdquo);", "”", RegexOptions.IgnoreCase);
    htmlString = Regex.Replace(htmlString, @"&#(d+);", "", RegexOptions.IgnoreCase);


    htmlString.Replace("<", "");
    htmlString.Replace(">", "");
    htmlString.Replace(" ", "");

    htmlString = HttpContext.Current.Server.HtmlEncode(htmlString).Trim();

    return htmlString;
    }

  • 相关阅读:
    乱谈服务器编程
    set global slow_query_log引起的MySQL死锁
    一个由string使用不当产生的问题
    Hbase初体验
    浅谈SQLite——查询处理及优化
    ACID、Data Replication、CAP与BASE
    libevent源码分析
    浅析Linux Native AIO的实现
    vim7.2中文乱码解决方法
    伸展树的点点滴滴
  • 原文地址:https://www.cnblogs.com/xinboqinheng/p/3823661.html
Copyright © 2011-2022 走看看