EasyASP - 简单好用的ASP类库框架

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 399|回复: 0

ASP过滤html函数只保留纯文字

[复制链接]

3

主题

7

帖子

59

积分

炼气期

Rank: 2

积分
59
发表于 2016-5-25 15:29:32 | 显示全部楼层 |阅读模式
[ASP,VB,VBS] 纯文本查看 复制代码
<%
Function RemoveHTML(strHTML)    '过滤HTML代码的函数包括过滤CSS和JS

StrHtml = Replace(StrHtml,vbCrLf,"") 
StrHtml = Replace(StrHtml,Chr(13)&Chr(10),"") 
StrHtml = Replace(StrHtml,Chr(13),"") 
StrHtml = Replace(StrHtml,Chr(10),"") 
StrHtml = Replace(StrHtml," ","") 
StrHtml = Replace(StrHtml,"    ","")

Dim objRegExp, Match, Matches 
Set objRegExp = New Regexp 

objRegExp.IgnoreCase = True 
objRegExp.Global = True

'取闭合的<> 
objRegExp.Pattern = "<style(.+?)/style>" 
'进行匹配 
Set Matches = objRegExp.Execute(strHTML) 

' 遍历匹配集合,并替换掉匹配的项目 
For Each Match in Matches 
strHtml=Replace(strHTML,Match.Value,"") 
Next

'取闭合的<> 
objRegExp.Pattern = "<script(.+?)/script>" 
'进行匹配 
Set Matches = objRegExp.Execute(strHTML) 

' 遍历匹配集合,并替换掉匹配的项目 
For Each Match in Matches 
strHtml=Replace(strHTML,Match.Value,"") 
Next

'取闭合的<> 
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

%>
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Lengshi Lincase Inc. ( 蜀ICP备05022485号-5

GMT+8, 2017-8-23 04:31 , Processed in 1.123090 second(s), 25 queries .

Powered by coldstone with Discuz! X

© 2008-2017 EasyASP.cn

快速回复 返回顶部 返回列表