asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

详解ASP.NET清除HTML标记的函数


发布日期:2018年03月05日
 
详解ASP.NET清除HTML标记的函数
//清除HTML函数

public static string NoHTML(string Htmlstring)

{

//删除脚本

Htmlstring = RegexReplace(Htmlstring @<script[^>]*?>*?</script> RegexOptionsIgnoreCase);

//删除HTML

Htmlstring = RegexReplace(Htmlstring @<([^>]*)> RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @([\r\n])[\s]+ RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @> RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @<!* RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(quot|#); \ RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(amp|#); & RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(lt|#); < RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(gt|#); > RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(nbsp|#); RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(iexcl|#); \xa RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(cent|#); \xa RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(pound|#); \xa RegexOptionsIgnoreCase);

Htmlstring = RegexReplace(Htmlstring @&(copy|#); \xa RegexOptionsIgnoreCase); Htmlstring = RegexReplace(Htmlstring @&#(\d+); RegexOptionsIgnoreCase);

HtmlstringReplace(< );

HtmlstringReplace(> );

HtmlstringReplace(\r\n );

Htmlstring = HttpContextCurrentServerHtmlEncode(Htmlstring)Trim();

return Htmlstring;

}                 

上一篇:提高ASP.Net应用程序性能的十大方法[2]

下一篇:ASP.NET入门教程 14.1.1 对象处理[1]