asp如何去除除了分段、分行和空格外的所有HTML标签

asp如何去除除了分段、分行和空格外的所有HTML标签,第1张

asp 分段分行空格还要啊。。。有点难。。

Function RemoveHTML( strText )

Dim RegEx

Set RegEx = New RegExp

RegEx.Pattern = "<[^>]*>"

RegEx.Global = True

str = RegEx.Replace(strText, "")

str=replace(str," ","")

RemoveHTML =str

End Function

‘这个是去所有的,当然太多了,那就在这个之前先将asp 分段分行和空格进行替换 <p>替换成{p},</p>替换成{/p},<br>替换成{br},空格替换成{&nbsp}

如 str="<p>123<br>"

str=replace(str,"<p>","{/p}")

...

...

str=RemoveHTML(str)

再替换回来

str=replace(str,"{/p}","<p>")

Function Zxj_ReplaceHtml(patrn, strng,content)

IF IsNull(content) Then

content=""

End IF

Set regEx = New RegExp

regEx.Pattern = patrn

regEx.IgnoreCase = true

regEx.Global = True

Zxj_ReplaceHtml=regEx.Replace(content,strng)

End Function

Function ClearHtml(Content)

Content=Zxj_ReplaceHtml("[^>]*", "", Content)

Content=Zxj_ReplaceHtml("</?marquee[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?object[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?param[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?embed[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?table[^>]*>", "", Content)

Content=Zxj_ReplaceHtml(" ","",Content)

Content=Zxj_ReplaceHtml("</?tr[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?th[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?p[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?a[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?img[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?tbody[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?li[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?span[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?div[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?th[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?td[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?script[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("(javascript|jscript|vbscript|vbs):", "", Content)

Content=Zxj_ReplaceHtml("on(mouse|exit|error|click|key)", "", Content)

Content=Zxj_ReplaceHtml("<\\?xml[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("<\/?[a-z]+:[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?font[^>]*>", "", Content)

Content=Zxj_ReplaceHtml("</?b[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?strong[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?u[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?i[^>]*>","",Content)

Content=Zxj_ReplaceHtml("</?xml[^>]*>", "", Content)

Content=trim(Content)

Content=replace(Content,chr(9),"")

Content=replace(Content,chr(32),"")

Content=replace(Content,chr(34),"")

Content=replace(Content,chr(39),"")

Content=replace(Content,chr(10),"")

Content=replace(Content,chr(13),"")

Content=replace(Content," ","")

Content=replace(Content,"\r\n","")

ClearHtml=Content

End Function


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7296229.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-04
下一篇 2023-04-04

发表评论

登录后才能评论

评论列表(0条)

保存