当前位置: 网学 > 编程文档 > ASP > 正文

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

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/06/16

【编者按】:网学网ASP为您提供asp中常用的字符串安全处理函数集合(过滤特殊字符等)参考,解决您在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)
IF Len(t0)=0 Or IsNull(t0) Or IsArray(t0) Then FilterHtml="":Exit Function
IF Len(Sdcms_Badhtml)>0 Then t0=ReplaceText(t0,"<(\/|)("&Sdcms_Badhtml&")", "<$1$2")
IF Len(Sdcms_BadEvent)>0 Then t0=ReplaceText(t0,"<(.[^>]*)("&Sdcms_BadEvent&")", "<$1$2")
t0=FilterText(t0,0)
FilterHtml=t0
End Funct

网学推荐

免费论文

原创论文

浏览:
设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
湘ICP备09003080号