sql html标签,如何在SQL语句中清除HTML标签?

满意答案

db="data.mdb"

set conn=server.createobject("Adodb.Connection")

connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db)

conn.open connstr

set rs=server.createobject("adodb.recordset")

sql="select * from 表"

rs.open sql,conn,1,3

do while rs.eof=false

rs("字段一")=Html2Ubb(rs("字段一")) '在这里使用Html2Ubb函数将字段的数据转换成纯文本形式后写入数据库

rs("字段二")=Html2Ubb(rs("字段二"))

rs("字段三")=Html2Ubb(rs("字段二"))

rs.update

rs.movenext

loop

rs.close

set rs=nothing

conn.close

set conn=nothing

Public Function Html2Ubb(ByVal strContent)

On Error Resume Next

If Len(strContent) > 0 Then

Dim re

Set re = New RegExp

re.IgnoreCase = True

re.Global = True

'--清除script脚本

If CInt(ArrayCodes(0)) = 1 Then

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有iframe框架

If CInt(ArrayCodes(1)) = 1 Then

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有object对象

If CInt(ArrayCodes(2)) = 1 Then

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有java applet

If CInt(ArrayCodes(3)) = 1 Then

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有div标签

If CInt(ArrayCodes(4)) = 1 Then

re.Pattern = "(

)|(
)"

strContent = re.Replace(strContent, "")

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有font标签

If CInt(ArrayCodes(5)) = 1 Then

re.Pattern = "()|()"

strContent = re.Replace(strContent, "")

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有span标签

If CInt(ArrayCodes(6)) = 1 Then

re.Pattern = "()|()"

strContent = re.Replace(strContent, "")

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有A标签

' If CInt(ArrayCodes(7)) = 1 Then

re.Pattern = "()|()"

strContent = re.Replace(strContent, "")

re.Pattern = "()"

strContent = re.Replace(strContent, "")

' End If

'--清除所有img标签

If CInt(ArrayCodes(8)) = 1 Then

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有FORM标签

If CInt(ArrayCodes(9)) = 1 Then

re.Pattern = "(

)|()"

strContent = re.Replace(strContent, "")

re.Pattern = "()"

strContent = re.Replace(strContent, "")

End If

'--清除所有HTML标签

If CInt(ArrayCodes(10)) = 1 Then

re.Pattern = "]*)>"

strContent = re.Replace(strContent, "")

End If

re.Pattern = "(" & Chr(8) & "|" & Chr(9) & "|" & Chr(10) & "|" & Chr(13) & ")"

strContent = re.Replace(strContent, vbNullString)

re.Pattern = "()"

strContent = re.Replace(strContent, vbNullString)

re.Pattern = "(

)"

strContent = re.Replace(strContent, "")

re.Pattern = "()"

strContent = re.Replace(strContent, "")

re.Pattern = "(

strContent = re.Replace(strContent, "

re.Pattern = "(" & Chr(37) & ">)"

strContent = re.Replace(strContent, "%>")

Set re = Nothing

Html2Ubb = strContent

Else

Html2Ubb = ""

End If

Exit Function

End Function

%>

00分享举报

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值