加入收藏 | 设为首页 | 会员中心 | 我要投稿 银川站长网 (https://www.0951zz.com/)- 云通信、基础存储、云上网络、机器学习、视觉智能!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

asp中日常的字符串安全处理函数集合 过滤特殊字符等

发布时间:2023-07-01 13:33:30 所属栏目:Asp教程 来源:
导读:asp中日常的字符串安全处理函数集合 过滤特殊字符等:代码如下:'====================================='转换内容,防止意外'=====================================Function Content_Encode(ByVal t0)I

asp中日常的字符串安全处理函数集合 过滤特殊字符等:

代码如下:

'=====================================

'转换内容,防止意外

'=====================================

Function Content_Encode(ByVal t0)

IF IsNull(t0) Or Len(t0)=0 Then

Content_Encode=""

Else

Content_Encode=Replace(t0,"<","<")

Content_Encode=Replace(Content_Encode,">",">")

End IF

End Function

'=====================================

'反转换内容

'=====================================

Function Content_Decode(ByVal t0)

IF IsNull(t0) Or Len(t0)=0 Then

Content_Decode=""

Else

Content_Decode=Replace(t0,"<","<")

Content_Decode=Replace(Content_Decode,">",">")

End IF

End Function

'=====================================

'过滤字符

'=====================================

Function FilterText(ByVal t0,ByVal t1)

IF Len(t0)=0 Or IsNull(t0) Or IsArray(t0) Then FilterText="":Exit Function

t0=Trim(t0)

Select Case t1

Case "1"

t0=Replace(t0,Chr(32)," ")

t0=Replace(t0,Chr(13),"")

t0=Replace(t0,Chr(10)&Chr(10),"<br>")

t0=Replace(t0,Chr(10),"<br>")

Case "2"

t0=Replace(t0,Chr(8),"")'回格

t0=Replace(t0,Chr(9),"")'tab(水平制表符)

t0=Replace(t0,Chr(10),"")'换行

t0=Replace(t0,Chr(11),"")'tab(垂直制表符)

t0=Replace(t0,Chr(12),"")'换页

t0=Replace(t0,Chr(13),"")'回车 chr(13)&chr(10) 回车和换行的组合

t0=Replace(t0,Chr(22),"")

t0=Replace(t0,Chr(32),"")'空格 SPACE

t0=Replace(t0,Chr(33),"")'!

t0=Replace(t0,Chr(34),"")'"

t0=Replace(t0,Chr(35),"")'#

t0=Replace(t0,Chr(36),"")'$

t0=Replace(t0,Chr(37),"")'%

t0=Replace(t0,Chr(38),"")'&

t0=Replace(t0,Chr(39),"")''

t0=Replace(t0,Chr(40),"")'(

t0=Replace(t0,Chr(41),"")')

t0=Replace(t0,Chr(42),"")'*

t0=Replace(t0,Chr(43),"")'+

t0=Replace(t0,Chr(44),"")',

t0=Replace(t0,Chr(45),"")'-

t0=Replace(t0,Chr(46),"")'.

t0=Replace(t0,Chr(47),"")'/

t0=Replace(t0,Chr(58),"")':

t0=Replace(t0,Chr(59),"")';

t0=Replace(t0,Chr(60),"")'<

t0=Replace(t0,Chr(61),"")'=

t0=Replace(t0,Chr(62),"")'>

t0=Replace(t0,Chr(63),"")'?

t0=Replace(t0,Chr(64),"")'@

t0=Replace(t0,Chr(91),"")'/

t0=Replace(t0,Chr(92),"")'/

t0=Replace(t0,Chr(93),"")']

t0=Replace(t0,Chr(94),"")'^

t0=Replace(t0,Chr(95),"")'_

t0=Replace(t0,Chr(96),"")'`

t0=Replace(t0,Chr(123),"")'{

t0=Replace(t0,Chr(124),"")'|

t0=Replace(t0,Chr(125),"")'}

t0=Replace(t0,Chr(126),"")'~

Case Else

t0=Replace(t0, "&", "&")

t0=Replace(t0, "'", "'")

t0=Replace(t0, """", """)

t0=Replace(t0, "<", "<")

t0=Replace(t0, ">", ">")

End Select

IF Instr(Lcase(t0),"expression")>0 Then

t0=Replace(t0,"expression","e­xpression", 1, -1, 0)

End If

FilterText=t0

End Function

'=====================================

'过滤常见字符及Html

'=====================================

Function FilterHtml(ByVal t0)

(编辑:银川站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章