C#过滤HTML代码
2008-06-30 18:06
246 查看
public string NoHTML(string Htmlstring) //去除HTML标记 { //删除脚本 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.Replace("<",""); Htmlstring.Replace(">",""); Htmlstring.Replace("/r/n",""); Htmlstring=HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim(); return Htmlstring; } |
相关文章推荐
- 一个用C#过滤HTML代码的函数
- C#过滤HTML代码
- 一个用c#过滤html代码的函数
- C#中用正则表达示过滤出HTML代码中的所有图片
- 用C#过滤HTML代码的函数【转自www.bitsCN.com】
- c#过滤HTML代码
- 一个用C#过滤HTML代码的函数
- C#中如何过滤掉多余的html代码
- 一个用C#过滤HTML代码的函数
- 一个用C#过滤HTML代码的函数
- 用C#过滤HTML代码的函数。
- 一个用C#过滤HTML代码的函数
- 关于C#中关于List.where中过滤条件的使用注意事项--笔记
- C#实现ip 地址过滤功能
- C#过滤XML(十六进制值 0x1D)无效的字符
- C#发送消息过滤关键字
- C# 过滤脚本_
- 为新闻内容截字而写的过滤HTML的C#方法
- C# 正则表达式过滤危险HTML
- C#(去、过滤)掉字符中的换行符