/// <summary>
/// 清除文本中Html的标签
/// </summary>
/// <param name="Content"></param>
/// <returns></returns>
protected string ClearHtml(string Content)
{
Content = ReplaceHtml("&#[^>]*;", "", Content);
Content = ReplaceHtml("</?marquee[^>]*>", "", Content);
Content = ReplaceHtml("</?object[^>]*>", "", Content);
Content = ReplaceHtml("</?param[^>]*>", "", Content);
Content = ReplaceHtml("</?embed[^>]*>", "", Content);
Content = ReplaceHtml("</?table[^>]*>", "", Content);
Content = ReplaceHtml(" ", "", Content);
Content = ReplaceHtml("</?tr[^>]*>", "", Content);
Content = ReplaceHtml("</?th[^>]*>", "", Content);
Content = ReplaceHtml("</?p[^>]*>", "", Content);
Content = ReplaceHtml("</?a[^>]*>", "", Content);
Content = ReplaceHtml("</?img[^>]*>", "", Content);
Content = ReplaceHtml("</?tbody[^>]*>", "", Content);
Content = ReplaceHtml("</?li[^>]*>", "", Content);
Content = ReplaceHtml("</?span[^>]*>", "", Content);
Content = ReplaceHtml("</?div[^>]*>", "", Content);
Content = ReplaceHtml("</?th[^>]*>", "", Content);
Content = ReplaceHtml("</?td[^>]*>", "", Content);
Content = ReplaceHtml("</?script[^>]*>", "", Content);
Content = ReplaceHtml("(javascript|jscript|vbscript|vbs):", "", Content);
Content = ReplaceHtml("on(mouse|exit|error|click|key)", "", Content);
Content = ReplaceHtml("<\\?xml[^>]*>", "", Content);
Content = ReplaceHtml("<\\/?[a-z]+:[^>]*>", "", Content);
Content = ReplaceHtml("</?font[^>]*>", "", Content);
Content = ReplaceHtml("</?b[^>]*>", "", Content);
Content = ReplaceHtml("</?u[^>]*>", "", Content);
Content = ReplaceHtml("</?i[^>]*>", "", Content);
Content = ReplaceHtml("</?strong[^>]*>", "", Content);
string clearHtml = Content;
return clearHtml;
}
/// <summary>
/// 清除文本中的Html标签
/// </summary>
/// <param name="patrn">要替换的标签正则表达式</param>
/// <param name="strRep">替换为的内容</param>
/// <param name="content">要替换的内容</param>
/// <returns></returns>
private string ReplaceHtml(string patrn, string strRep, string content)
{
if (string.IsNullOrEmpty(content))
{
content = "";
}
Regex rgEx = new Regex(patrn, RegexOptions.IgnoreCase);
string strTxt = rgEx.Replace(content, strRep);
return strTxt;
}

清除文本中Html的标签的更多相关文章

  1. C# 清除文本中的HTML标签

    /// <summary>          /// 清除文本中Html的标签          /// </summary>          /// <param n ...

  2. js 清除文本中的html标签

    text.replace(/<[^>]+>/g,"");

  3. 去除富文本中的html标签及vue、react、微信小程序中的过滤器

    在获取富文本后,又只要显示部分内容,需要去除富文本标签,然后再截取其中一部分内容:然后就是过滤器,在微信小程序中使用还是挺多次的,在vue及react中也遇到过 1.富文本去除html标签 去除htm ...

  4. python去除文本中的HTML标签

    def SplitHtmlTag(file): with open(file,"r") as f,open("result.txt","w+" ...

  5. Android检测富文本中的<img标签并实现点击效果

    本文旨在:通过点击一张图片Toast输出位置与url链接. 闲话少说,实现原理大概是酱紫的::通过正则表达式检测富文本内的图片集合并获取url,在src=“xxx” 后面添加 onclick方法,至于 ...

  6. 清除大文本中的html标签

    public String clearHtmlText(String inputString) { if (StringUtils.isBlank(inputString)) { return &qu ...

  7. 过滤掉文本中的javascript标签代码

    2014年1月21日 11:51:19 php代码: $content = preg_replace('#<\s*[script].*>#', '', $a);//有些攻击可以在scrip ...

  8. HTML中的图片标签的用法!

    在HTML中<img>这个标签是定义文本中的图片标签,它的作用就比如说可以提供图片的名字.提供图片的尺寸大小和提供图片的一些图片属性,比如Alt这个属性,可以给图片一个名称来告诉朋友们.这 ...

  9. 如何使用JS脚本从HTML中分离图片标签与文本,替换文本中指定的内容并加粗(原创)

    var html='ddfsdfsdfdsd dfsdfsdffds<img _src="http://localhost:8490/60E86EA7-FE7B-44BF-8270-4 ...

随机推荐

  1. HanLP-基于HMM-Viterbi的人名识别原理介绍

    Hanlp自然语言处理包中的基于HMM-Viterbi处理人名识别的内容大概在年初的有分享过这类的文章,时间稍微久了一点,有点忘记了.看了 baiziyu 分享的这篇比我之前分享的要简单明了的多.下面 ...

  2. java微信token校验

    1.微信验证接口 package com.park.utils.wechatUtil; import org.springframework.web.bind.annotation.RequestMa ...

  3. 创建Vofuria工程,获取产品密钥

    进入Vofuria官网 https://developer.vuforia.com/vui/develop/licenses/free/new 然后点击 然后在License Name中填写izji刚 ...

  4. Photon Server初识(六) --- 客户端与服务端消息传递

    前一章客户端与服务端连接成功,现在需要前后端进行数据传递. 一.前端发送消息.在项目Scripts目录中新建脚本 TestSer.cs.并挂载到相机上 二.客户端发送数据给服务端.编辑客户端代码 Te ...

  5. 【思维】ABC

    题目描述 You are given a string s consisting of A, B and C.Snuke wants to perform the following operatio ...

  6. SimpleDateFormat线程安全问题

    今天线上出现了问题,从第三方获取的日期为 2019-12-12 11:11:11,通过SimpleDateFormat转换格式后,竟然出现完全不正常的日期数据,经百度,得知SimpleDateForm ...

  7. 【QT学习笔记】二、信号槽和自定义信号槽

    1. 信号槽 int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton button("Qui ...

  8. LeetCode:596.超过5名学生的课

    题目链接:https://leetcode-cn.com/problems/classes-more-than-5-students/ 题目 有一个 courses 表 ,有: student (学生 ...

  9. 使用百度地图API自动获取地址和经纬度

    先上效果图,这是直接点击获取经纬度和地址的.没有做搜索的功能. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...

  10. 6.移动端自动化测试-小知识 if __name__==’__main__:是什么意思?

    1 引言 在Python当中,如果代码写得规范一些,通常会写上一句“if __name__==’__main__:”作为程序的入口,但似乎没有这么一句代码,程序也能正常运行.这句代码多余吗?原理又在哪 ...