html中清除所有格式,清除文件HTML格式函数ClearHtml

本文介绍了一个名为ClearHtmlReplaceHtml的VBScript函数,用于清除HTML文件中的特定标签和格式,如<script>、<img>等,通过正则表达式实现数据清理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

'/* 函数名称:ClearHtml ReplaceHtml

'/* 函数语言:VBScript Language

'/* 作  用:清除文件HTML格式函数

'/* 传递参数:Content (注:需要进行清除的内容)

'/* 函数作者:auuo.com

'/* 函数说明:正则匹配(正则表达式)模式进行数据匹配替换

Function ClearHtml(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("]*>", "", Content)

Content=ReplaceHtml("]*>", "", Content)

Content=ReplaceHtml("?font[^>]*>", "", Content)

Content=ReplaceHtml("?b[^>]*>","",Content)

Content=ReplaceHtml("?u[^>]*>","",Content)

Content=ReplaceHtml("?i[^>]*>","",Content)

Content=ReplaceHtml("?strong[^>]*>","",Content)

ClearHtml=Content

End Function

Function ReplaceHtml(patrn, strng,content)

IF IsNull(content) Then

content=""

End IF

Set regEx = New RegExp ' 建立正则表达式。

regEx.Pattern = patrn ' 设置模式。

regEx.IgnoreCase = true       ' 设置忽略字符大小写。

regEx.Global = True ' 设置全局可用性。

ReplaceHtml=regEx.Replace(content,strng) ' 执行正则匹配

End Function

Function RemoveHTML(strHTML)

Dim objRegExp, Match, Matches

Set objRegExp = New Regexp

objRegExp.IgnoreCase = True

objRegExp.Global = True

'取闭合的<>

objRegExp.Pattern = "<.>"

'进行匹配

Set Matches = objRegExp.Execute(strHTML)

' 遍历匹配集合,并替换掉匹配的项目

For Each Match in Matches

strHtml=Replace(strHTML,Match.Value,"")

Next

RemoveHTML=strHTML

Set objRegExp = Nothing

End Function

%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值