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;
    }
  • 相关阅读:
    Python3之命令行参数处理
    基于 Laradock 环境 Project 的总结
    Typora功能新发现-自动复制图片到指定目录下
    ubuntu 18.04 设置静态ip方法
    vscode 同时编辑多处,多个光标 快捷键
    nginx和ftp搭建图片服务器
    Centos 6.5出现yum安装慢的情况
    Linux中的CentOS 6克隆之后修改
    springMVC-文件上传CommonsMultipartFile
    Spring和mybatis整合 org.mybatis.spring.mapper.MapperScannerConfigurer
  • 原文地址:https://www.cnblogs.com/muxueyuan/p/4482071.html
Copyright © 2011-2022 走看看