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;
    }

  • 相关阅读:
    文件处理seek以及修改内容的两种方式
    三元表达式、列表推导式、生成器表达式、递归、匿名函数、内置函数
    MySQL逻辑查询语句执行顺序
    函数基础
    迭代器、生成器、面向过程编程
    3 函数
    文件处理
    字符编码
    2 数据类型、字符编码、文件处理
    转载文章之提供给开发者 10 款最好的 Python IDE
  • 原文地址:https://www.cnblogs.com/xinboqinheng/p/3823661.html
Copyright © 2011-2022 走看看