c# 过滤html
2024-09-13 09:28:41
public static string StripHTML(string html) { try { System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" on[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase); html = regex1.Replace(html, ""); //过滤<script></script>标记 html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性 html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on事件 html = regex4.Replace(html, ""); //过滤iframe html = regex5.Replace(html, ""); //过滤frameset html = regex6.Replace(html, ""); //过滤frameset html = regex7.Replace(html, ""); //过滤frameset html = regex8.Replace(html, ""); //过滤frameset html = html.Replace(" ", ""); html = html.Replace("</strong>", ""); html = html.Replace("<strong>", ""); html = html.Replace("\r", ""); html = html.Replace("\n", ""); html = html.Replace("'", ""); html = html.Replace("\"", ""); html = html.Replace("\t", ""); return html; } catch { //MessageBox.Show("Error"); return html; } }
最新文章
- Linux--Tail命令
- Eclipse迁移到Android studio步骤如下:
- easyui tree onloadsuccess事件的心得
- 【BZOJ-1176&;2683】Mokia&;简单题 CDQ分治
- 加州大学伯克利分校Stat2.3x Inference 统计推断学习笔记: Section 1 Estimating unknown parameters
- hdu5432 二分
- $parse/$eval和$observe/$watch如何区分
- Tarjan求极大强连通分量模板
- NAT ALG原理
- 面试题 ARC
- ProjectA: 多元非线性回归
- FSG报表打印报错,log文件显示java.sql.SQLException: No corresponding LOB data found
- cuda中模板的使用
- MacOS搭建本地服务器
- 关于PHP上传文件时配置 php.ini 中的 upload_tmp_dir
- 1、Nexus安装
- django学习,session与cookie
- 20190402Linux常用命令week1.1
- 30.Mysql常见问题和应用技巧
- JavaScript 频繁发射事件处理的优化 --- 函数节流/事件稀释
热门文章
- 2019.02.28 bzoj4199: [Noi2015]品酒大会(sam+线段树)
- java生成pdf文件 --- Table
- (PMP)第11章-----项目风险管理
- VUE 动态给对象增加属性,并触发视图更新。
- 去掉input[type=";number";]的默认样式
- 居于H5的多文件、大文件、多线程上传解决方案
- zookeeper学习day01
- MFC控件的颜色设置
- 你可能不知道的github语法——图标
- sublime text 3中安装ctags支持函数跳转,安装convertToUtf8支持中文步骤[工具篇]