查看: 831|回复: 4
|
ASP如何filter特定的htmlcode?
[复制链接]
|
|
strInput = request.form("txtInput")
我要如何filter所有的strInput 的 htmlCode,如 <frame> 和 javascript?
但allow strInput 有 <table>, <img> 等等...
但如何确保strInput 的 <table> 一定 要 </table>
谢谢... |
|
|
|
|
|
|
|
发表于 9-6-2007 01:00 PM
|
显示全部楼层
原帖由 Stephy 于 9-6-2007 02:34 AM 发表
strInput = request.form("txtInput"
我要如何filter所有的strInput 的 htmlCode,如 <frame> 和 javascript?
但allow strInput 有 <table>, <img> 等等...
但如何确保strInpu ...
asp 我不会。。之前是用asp.net 的。。不过concept 都是一样的。。
我是用string.replace... 先把string 变成char array.. 然后拿到"<“的char index.. 再拿">" 的index.. 然后把它们还有中间的char全部replace 成" ".. .虽然方法是愚蠢点。。 不过应该有用。。 |
|
|
|
|
|
|
|
发表于 13-6-2007 05:48 PM
|
显示全部楼层
我自己写的,希望可以帮到你:
Function removeTag(sStr)
Dim obj, oCol, sOut, arrTag, i
sOut = sStr
arrTag = Array("FORM","SCRIPT")'要丢掉的 Html Code
For i = 0 to ubound(arrTag)
Set oCol = getMatches("<" & arrTag(i) & ".*?>", sStr)
For Each obj In oCol
sOut = Replace(sOut,obj,"")
Next
Set oCol = getMatches("<\/" & arrTag(i) & ">", sStr)
For Each obj In oCol
sOut = Replace(sOut,obj,"")
Next
Set oCol = Nothing
Next
removeTag = sOut
End Function
Function getMatches(patrn, strng)
Dim retStr, regEx
Set regEx = New RegExp
regEx.Pattern = patrn
regEx.IgnoreCase = True
regEx.Global = True
Set getMatches = regEx.Execute(strng)
End Function |
|
|
|
|
|
|
|
发表于 16-6-2007 04:35 PM
|
显示全部楼层
试一试 smallsotong 的方法。

[ 本帖最后由 梦中说梦 于 16-6-2007 04:39 PM 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 17-6-2007 12:59 AM
|
显示全部楼层
原帖由 smallsotong 于 13-6-2007 05:48 PM 发表
我自己写的,希望可以帮到你:
Function removeTag(sStr)
Dim obj, oCol, sOut, arrTag, i
sOut = sStr
arrTag = Array("FORM","SCRIPT" '要丢掉的 Html Co ...
多谢了... 是我要的...
但如何确保user开了<B>一定要</B>??? |
|
|
|
|
|
|
| |
本周最热论坛帖子
|