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;
    }
  • 相关阅读:
    【Foreign】数数 [打表][DP]
    【Foreign】猜测 [费用流]
    【Foreign】最大割 [线性基]
    【Foreign】开锁 [概率DP]
    【Foreign】染色 [LCT][线段树]
    【Foreign】阅读 [线段树][DP]
    【Foreign】字符串匹配 [KMP]
    【Foreign】冒泡排序 [暴力]
    【BZOJ1976】能量魔方 [最小割]
    【Foreign】树 [prufer编码][DP]
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/4482071.html
Copyright © 2011-2022 走看看