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

  • 相关阅读:
    Django测试开发-36- xadmin模板中缩略图django-stdimage
    Django测试开发-35- xadmin模板中添加上传文件和图片功能
    Django测试开发-34- xadmin模板中添加action插件
    Django测试开发-33- xadmin模板中添加小组件报错
    Django测试开发-32- xadmin模板使用自定义菜单项
    Django测试开发-31- xadmin模板中choices使用
    序列化模块
    一大群模块
    python基础之内置函数和匿名函数
    python基础之迭代器和生成器
  • 原文地址:https://www.cnblogs.com/xinboqinheng/p/3823661.html
Copyright © 2011-2022 走看看