ASP仿PHP的一些常用函数


ASP #函数2012-05-11 11:46
001'过程:输出字符串[代替Response.Write]
002 
003Sub echo(Str)
004response.Write(Str)
005End Sub
006 
007'函数:获取表单[代替Request.Form]
008 
009Function reqf(Str)
010reqf = Request.Form(Str)
011End Function
012 
013'过程:结束页面并输出字符串
014 
015Sub die(Str)
016response.Write(Str)
017response.End()
018End Sub
019 
020'函数:将ASP文件运行结果返回为字串
021 
022Function ob_get_contents(Path)
023Dim tmp, a, b, t, matches, m
024Dim Str
025Str = file_iread(Path)
026tmp = "dim htm : htm = """""&vbCrLf;
027a = 1
028b = InStr(a, Str, "<%") + 2
029While b > a + 1
030t = Mid(Str, a, b - a -2)
031t = Replace(t, vbCrLf, "{::vbcrlf}")
032t = Replace(t, vbCr, "{::vbcr}")
033t = Replace(t, """", """""")
034tmp = tmp & "htm = htm & """ & t & """" & vbCrLf
035a = InStr(b, Str, "%\>") + 2
036tmp = tmp & str_replace("^\s*=", Mid(Str, b, a - b -2), "htm = htm & ") & vbCrLf
037b = InStr(a, Str, "<%") + 2
038Wend
039t = Mid(Str, a)
040t = Replace(t, vbCrLf, "{::vbcrlf}")
041t = Replace(t, vbCr, "{::vbcr}")
042t = Replace(t, """", """""")
043tmp = tmp & "htm = htm & """ & t & """" & vbCrLf
044tmp = Replace(tmp, "response.write", "htm = htm & ", 1, -1, 1)
045tmp = Replace(tmp, "echo", "htm = htm & ", 1, -1, 1)
046'execute(tmp)
047executeglobal(tmp)
048htm = Replace(htm, "{::vbcrlf}", vbCrLf)
049htm = Replace(htm, "{::vbcr}", vbCr)
050ob_get_contents = htm
051End Function
052 
053'过程:动态包含文件
054 
055Sub include(Path)
056echo ob_get_contents(Path)
057End Sub
058 
059'函数:base64加密
060 
061Function base64encode(byval Str)
062If IsNull(Str) Then Exit Function
063Dim base64
064Set base64 = New base64_class
065Str = base64.encode(Str)
066Set base64 = Nothing
067base64encode = Str
068End Function
069 
070'函数:base64解密
071 
072Function base64decode(byval Str)
073If IsNull(Str) Then Exit Function
074Dim base64
075Set base64 = New base64_class
076Str = base64.decode(Str)
077Set base64 = Nothing
078base64decode = Str
079End Function
080 
081'函数:URL加密
082 
083Function urlencode(byval Str)
084If IsNull(Str) Then Exit Function
085Str = server.URLEncode(Str)
086urlencode = Str
087End Function
088 
089'函数:Escape加密
090 
091Function escape(byval Str)
092If IsNull(Str) Then Exit Function
093Dim i, c, a, tmp
094tmp = ""
095For i = 1 To Len(Str)
096c = Mid(Str, i, 1)
097a = ascw(c)
098If (a>= 48 And a<= 57) Or (a>= 65 And a<= 90) Or (a>= 97 And a<= 122) Then
099tmp = tmp & c
100ElseIf InStr("@*_+-./", c) > 0 Then
101tmp = tmp & c
102ElseIf a>0 And a<16 Then
103tmp = tmp & "%0" & Hex(a)
104ElseIf a>= 16 And a<256 Then
105tmp = tmp & "%" & Hex(a)
106Else
107tmp = tmp & "%u" & Hex(a)
108End If
109Next
110escape = tmp
111End Function
112 
113'函数:Escape解密
114 
115Function unescape(byval Str)
116If IsNull(Str) Then Exit Function
117Dim i, c, tmp
118tmp = ""
119For i = 1 To Len(Str)
120c = Mid(Str, i, 1)
121If Mid(Str, i, 2) = "%u" And i<= Len(Str) -5 Then
122If IsNumeric("&H;" & Mid(Str, i + 2, 4)) Then
123tmp = tmp & chrw(CInt("&H;" & Mid(Str, i + 2, 4)))
124i = i + 5
125Else
126tmp = tmp & c
127End If
128ElseIf c = "%" And i<= Len(Str) -2 Then
129If IsNumeric("&H;" & Mid(Str, i + 1, 2)) Then
130tmp = tmp & chrw(CInt("&H;" & Mid(Str, i + 1, 2)))
131i = i + 2
132Else
133tmp = tmp & c
134End If
135Else
136tmp = tmp & c
137End If
138Next
139unescape = tmp
140End Function

相关文章

粤ICP备11097351号-1