过滤掉html 标签
2024-10-10 02:33:31
/// <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, @"([\r\n])[\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("\r\n", "");
htmlstring = HttpContext.Current.Server.HtmlEncode(htmlstring).Trim();
return htmlstring;
}
最新文章
- DDNS动态更新
- Eclipse里面的一些常规设置
- 64-who 简明笔记
- JavaScript 在不刷新或跳转页面的情况下改变当前浏览器地址栏上的网址
- [Leetcode][JAVA] Word Ladder
- [ACM_暴力] ZOJ 3710 [Friends 共同认识 最终认识 暴力]
- VS2008 调试记录
- HW4.17
- 重启iis线程池和iis站点
- 【MyBatis学习笔记】
- Android日志系统Logcat源代码简要分析
- git 使用详情
- Python之面向对象四
- mxGraph进阶(一)mxGraph教程-开发入门指南
- 『战略游戏 最大利润 树形DP』
- 面试中遇到的原生js题总结
- Python3.x - 字符串
- JDK1.7 高并发下的HashMap
- 【逆向工具】使用x64dbg+spy去除WinRAR5.40(64位)广告弹框
- 常用vimrc记录