在asp中传递参数时有一个很有用的系统函数server.urlencode,可以将一些非字母数字的特殊符号转换成标准url编码(其实就是16进制asc码),这样就解决了参数传递问题,然后我以为也提供了server.urldecode,但使用后却发现程序报错,原来系统并没有提供这个我想象中的解码函数。怎幺办,自己动手吧。
urlencode的原理其实很简单,就是将特殊字符转换成16进制asc码值,那么译码函数就只要将16进制asc转回对应的字符就ok了。
function urldecode(enstr) 'url解碼函數
dim destr
dim c,i,v
destr=""
for i=1 to len(enstr)
c=mid(enstr,i,1)
if c="%" then
v=eval("&h"+mid(enstr,i+1,2))
if v<128 then
destr=destr&chr(v)
i=i+2
else
if isvalidhex(mid(enstr,i,3)) then
if isvalidhex(mid(enstr,i+3,3)) then
v=eval("&h"+mid(enstr,i+1,2)+mid(enstr,i+4,2))
destr=destr&chr(v)
i=i+5
else
v=eval("&h"+mid(enstr,i+1,2)+cstr(hex(asc(mid(enstr,i+3,1)))))
destr=destr&chr(v)
i=i+3
end if
else
destr=destr&c
end if
end if
else
if c="+" then
destr=destr&" "
else
destr=destr&c
end if
end if
next
urldecode=destr
end function
function isvalidhex(str)
isvalidhex=true
str=ucase(str)
if len(str)<>3 then isvalidhex=false:exit function
if left(str,1)<>"%" then isvalidhex=false:exit function
c=mid(str,2,1)
if not (((c>="0") and (c<="9")) or ((c>="a") and (c<="z"))) then isvalidhex=false:exit function
c=mid(str,3,1)
if not (((c>="0") and (c<="9")) or ((c>="a") and (c<="z"))) then isvalidhex=false:exit function
end function
经测试gb312格式的asp使用没有问题。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!