过滤eWebeditor等富文本中html标签,获得纯文本信息
2014-03-31 13:13
621 查看
/// <summary> /// 过滤html标签 /// </summary> /// <param name="Htmlstring"></param> /// <returns></returns> public string ParseTags(string Htmlstring) { //删除脚本 Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase); //删除<style></style>样式 Htmlstring = Regex.Replace(Htmlstring, @"<style[^>]*?>[\s\S]*?</style>", "", 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; }
相关文章推荐
- 正确使用HTML title属性的一些建议
- html标准写法与dreamweaver自动生成的不一样
- 关于textarea中原格式输出html代码
- HTML 5 <embed> 标签
- 你绝对想要的HTML页面超链接的修改问题
- 关于HTML <!DOCTYPE> 标签的使用
- Web: html_entity_decode、空格&nbsp以及乱码
- html盒模型和位置的相关的图
- 返回到上一页的html代码的几种写法
- 颜色名称及色样表(HTML版)
- html注册表单与服务器
- HTML 5核心内容
- HTML 5核心内容
- HTML 5核心内容
- hdu 1088 HTML解析
- 在Java代码中输出html的信息使用out.println()
- HTML(2)
- HTML URL编码,这个是地址栏常看到的知识
- HTML统一资源定位器——html的url知识
- HTML 基本结构