zoukankan      html  css  js  c++  java
  • 过滤掉html 标签

    /// <summary>
    /// 过滤掉html标签
    /// </summary>
    /// <param name="Htmlstring"></param>
    /// <returns></returns>
    public static string RemoveHTML(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, @"&#(d+);", "", RegexOptions.IgnoreCase);
    htmlstring = Regex.Replace(htmlstring, @"<img[^>]*>;", "", RegexOptions.IgnoreCase);
    htmlstring = htmlstring.Replace("<", "");
    htmlstring = htmlstring.Replace(">", "");
    htmlstring = htmlstring.Replace("
    ", "");
    htmlstring = HttpContext.Current.Server.HtmlEncode(htmlstring).Trim();
    return htmlstring;
    }
  • 相关阅读:
    JavaScript 闭包
    JavaScript for循环
    JavaScript switch语句
    JavaScript if...else 语句
    JavaScript流程控制语句脑图
    JavaScript比较和逻辑运算符
    JavaScript运算符
    记录一下获取浏览器可视区域的大小的js
    20181016记录一次前端布局
    20181015记录一个简单的TXT日志类
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/4482071.html
Copyright © 2011-2022 走看看