如何屏蔽掉所有的html代码?

12301230 2003-10-10 07:10:37
我要从数据库中取出用web页面编辑的文档,并要截取一部分内容,但不要领先地位任何html代码,没搞好,哪位朋友可以告诉?

Function FilterHTML(strToFilter)
Dim strTemp
strTemp = strToFilter
While Instr(1,strTemp,"<") AND Instr(1, strTemp, ">")
strTemp = Left(strTemp, Instr(1, strTemp, "<")-1) & Right(strTemp, Len(strTemp)-Instr(1,strTemp, ">"))
WEnd
FilterHTML = strTemp
End Function

用这个好象过滤不好,如<font>ggggg ttyyy</font>就过滤不</font>掉,请看有无错误?
...全文
220 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
qunluo 2003-10-12
  • 打赏
  • 举报
回复
gz
chinahuman 2003-10-12
  • 打赏
  • 举报
回复
把所有的HTML代码过滤掉后再取你所要的东西
chinahuman 2003-10-12
  • 打赏
  • 举报
回复
楼上的太麻烦了,只要html.encode()一下就可以了!
smuzy 2003-10-12
  • 打赏
  • 举报
回复
Function remove_HTMLtags(str1)
str1 = Replace(str1, vbCrLf, "") '先去掉换行和空格
Dim regEx
set regEx=New RegExp '建立正则表达式。
regEx.Global = True
regEx.IgnoreCase = True ' 设置是否区分大小写。

regEx.Pattern = "<.*?>" ' 设置模式。
remove_HTMLtags = regEx.Replace(str1, "") ' 作替换。
remove_HTMLtags = Trim(remove_HTMLtags)
Set regEx = Nothing
End Function
avonqin 2003-10-11
  • 打赏
  • 举报
回复
marking
12301230 2003-10-11
  • 打赏
  • 举报
回复
xishanlang2001(西山狼2000) 说的有道理,不知能否过滤掉word粘贴过来的代码,我再调调。多谢了!
yangzixp 2003-10-10
  • 打赏
  • 举报
回复
我的:
Function stripHTML(strHTML)
'Strips the HTML tags from strHTML

Dim objRegExp, strOutput
Set objRegExp = New Regexp

objRegExp.IgnoreCase = True
objRegExp.Global = True
objRegExp.Pattern = "<.+?>"
'objRegExp.Pattern = "<.[^\[]*>"


'Replace all HTML tag matches with the empty string
strOutput = objRegExp.Replace(strHTML, "")

'Replace all < and > with < and >
strOutput = objRegExp.Replace(strHTML, "")

'Replace all < and > with < and >
strOutput = Replace(strOutput, "<", "<")
strOutput = Replace(strOutput, ">", ">")

stripHTML = strOutput 'Return the value of strOutput

Set objRegExp = Nothing
End Function

不过要求服务器:ie6+sp3
xishanlang2001 2003-10-10
  • 打赏
  • 举报
回复
<script language=vbscript>
Function FilterHTML(strToFilter)
Dim strTemp,strTemppart1
strTemp = strToFilter
While Instr(1,strTemp,"<")<>0 AND Instr(1, strTemp, ">")<>0
strTemp = Left(strTemp, Instr(1, strTemp, "<")-1) & Right(strTemp, Len(strTemp)-Instr

(1,strTemp, ">"))
WEnd
FilterHTML = strTemp
End Function
msgbox(FilterHTML("<font>ggggg ttyyy</font>"))
</script>


没有问题呀.
While Instr(1,strTemp,"<") AND Instr(1, strTemp, ">")
改成
While Instr(1,strTemp,"<")<>0 AND Instr(1, strTemp, ">")<>0

试了一下,好象while和if不一样,不能是0直接认为条件不成立.

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧