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;
    }
  • 相关阅读:
    选择学习Web前端开发的理由
    在Nginx下部署SSL证书并重定向至HTTPS
    使用pm2快速将项目部署到远程服务器
    DNS域名解析过程
    HTML5新特性总结
    基于 HTML5 Canvas 的智能安防 SCADA 巡逻模块
    react中使用css的7种方式
    原生JS实现滑动轮播图
    H5与企业微信jssdk集成
    img图片不存在显示默认图
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/4482071.html
Copyright © 2011-2022 走看看