当前位置: 移动技术网 > IT编程>开发语言>Asp > asp仿php的一些函数分享

asp仿php的一些函数分享

2017年12月08日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

'过程:输出字符串[代替response.write]

sub echo(str)
response.write(str)
end sub

'函数:获取表单[代替request.form]

function reqf(str)
reqf = request.form(str)
end function

'过程:结束页面并输出字符串

sub die(str)
response.write(str)
response.end()
end sub

'函数:将asp文件运行结果返回为字串

function ob_get_contents(path)
dim tmp, a, b, t, matches, m
dim str
str = file_iread(path)
tmp = "dim htm : htm = """""&vbcrlf
a = 1
b = instr(a, str, "<%") + 2
while b > a + 1
t = mid(str, a, b - a -2)
t = replace(t, vbcrlf, "{::vbcrlf}")
t = replace(t, vbcr, "{::vbcr}")
t = replace(t, """", """""")
tmp = tmp & "htm = htm & """ & t & """" & vbcrlf
a = instr(b, str, "%\>") + 2
tmp = tmp & str_replace("^\s*=", mid(str, b, a - b -2), "htm = htm & ") & vbcrlf
b = instr(a, str, "<%") + 2
wend
t = mid(str, a)
t = replace(t, vbcrlf, "{::vbcrlf}")
t = replace(t, vbcr, "{::vbcr}")
t = replace(t, """", """""")
tmp = tmp & "htm = htm & """ & t & """" & vbcrlf
tmp = replace(tmp, "response.write", "htm = htm & ", 1, -1, 1)
tmp = replace(tmp, "echo", "htm = htm & ", 1, -1, 1)
'execute(tmp)
executeglobal(tmp)
htm = replace(htm, "{::vbcrlf}", vbcrlf)
htm = replace(htm, "{::vbcr}", vbcr)
ob_get_contents = htm
end function

'过程:动态包含文件

sub include(path)
echo ob_get_contents(path)
end sub

'函数:base64加密

function base64encode(byval str)
if isnull(str) then exit function
dim base64
set base64 = new base64_class
str = base64.encode(str)
set base64 = nothing
base64encode = str
end function

'函数:base64解密

function base64decode(byval str)
if isnull(str) then exit function
dim base64
set base64 = new base64_class
str = base64.decode(str)
set base64 = nothing
base64decode = str
end function

'函数:url加密

function urlencode(byval str)
if isnull(str) then exit function
str = server.urlencode(str)
urlencode = str
end function

'函数:escape加密

function escape(byval str)
if isnull(str) then exit function
dim i, c, a, tmp
tmp = ""
for i = 1 to len(str)
c = mid(str, i, 1)
a = ascw(c)
if (a>= 48 and a<= 57) or (a>= 65 and a<= 90) or (a>= 97 and a<= 122) then
tmp = tmp & c
elseif instr("@*_+-./", c) > 0 then
tmp = tmp & c
elseif a>0 and a<16 then
tmp = tmp & "%0" & hex(a)
elseif a>= 16 and a<256 then
tmp = tmp & "%" & hex(a)
else
tmp = tmp & "%u" & hex(a)
end if
next
escape = tmp
end function

'函数:escape解密

function unescape(byval str)
if isnull(str) then exit function
dim i, c, tmp
tmp = ""
for i = 1 to len(str)
c = mid(str, i, 1)
if mid(str, i, 2) = "%u" and i<= len(str) -5 then
if isnumeric("&h" & mid(str, i + 2, 4)) then
tmp = tmp & chrw(cint("&h" & mid(str, i + 2, 4)))
i = i + 5
else
tmp = tmp & c
end if
elseif c = "%" and i<= len(str) -2 then
if isnumeric("&h" & mid(str, i + 1, 2)) then
tmp = tmp & chrw(cint("&h" & mid(str, i + 1, 2)))
i = i + 2
else
tmp = tmp & c
end if
else
tmp = tmp & c
end if
next
unescape = tmp
end function

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网