C# 过滤html标签
2020-12-13 04:08
标签:blog class c code java ext " C# 过滤html标签,搜素材,soscw.com C# 过滤html标签 标签:blog class c code java ext 原文地址:http://www.cnblogs.com/qk2014/p/3731587.html
public
static string checkStr(string
html)
{
System.Text.RegularExpressions.Regex regex1 = new
System.Text.RegularExpressions.Regex(@", 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(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new
System.Text.RegularExpressions.Regex(@", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new
System.Text.RegularExpressions.Regex(@", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new
System.Text.RegularExpressions.Regex(@"\]+\>"
, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new
System.Text.RegularExpressions.Regex(@"", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new
System.Text.RegularExpressions.Regex(@", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new
System.Text.RegularExpressions.Regex(@"]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex10 = new
System.Text.RegularExpressions.Regex(@"[\t\n\r\s]", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤标记
html = regex2.Replace(html, ""); //过滤href=javascript: () 属性
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 = regex9.Replace(html, "");
html = regex10.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace(" ", "");
html = html.Replace("‘", "‘‘"); //转义单引号
html = html.Replace("", "");
html = html.Replace("", "");
return
html;
}
下一篇:Python学习第五天