ASP中文URL解码URLDecode函数实现
大家都知道,在asp中,我们一般都通过Server.UrlEncode进行url的编码,这样使得一些特殊的字符能够通过链接正常访问,但当我们把这个编码后的url字符存入数据库后,有些时候需要程序读取这个url进行处理时,就需要对其进行url解码,在php中这些功能很完善,但asp中,我们是找不到Server.UrlDecode函数的,鉴于这个问题,我们就要自己写一个解码函数了,以下是一段支持中文URLDecode的Asp函数,可以基于这个函数将其写成一个类,呵呵,这里就不细说了。
<%
functionURLDecode(strIn)
URLDecode=""
Dimsl:sl=1
Dimtl:tl=1
Dimkey:key="%"
Dimkl:kl=Len(key)
sl=InStr(sl,strIn,key,1)
DoWhilesl>0
If(tl=1Andsl<>1)Ortl<slThen
URLDecode=URLDecode&Mid(strIn,tl,sl-tl)
EndIf
Dimhh,hi,hl
Dima
SelectCaseUCase(Mid(strIn,sl+kl,1))
Case"U":'UnicodeURLEncode
a=Mid(strIn,sl+kl+1,4)
URLDecode=URLDecode&ChrW("&H"&a)
sl=sl+6
Case"E":'UTF-8URLEncode
hh=Mid(strIn,sl+kl,2)
a=Int("&H"&hh)'ascii码
IfAbs(a)<128Then
sl=sl+3
URLDecode=URLDecode&Chr(a)
Else
hi=Mid(strIn,sl+3+kl,2)
hl=Mid(strIn,sl+6+kl,2)
a=("&H"&hhAnd&H0F)*2^12Or("&H"&hiAnd&H3F)*2^6Or("&H"&hlAnd&H3F)
Ifa<0Thena=a+65536
URLDecode=URLDecode&ChrW(a)
sl=sl+9
EndIf
CaseElse:'AscURLEncode
hh=Mid(strIn,sl+kl,2)'高位
a=Int("&H"&hh)'ascii码
IfAbs(a)<128Then
sl=sl+3
Else
hi=Mid(strIn,sl+3+kl,2)'低位
a=Int("&H"&hh&hi)'非ascii码
sl=sl+6
EndIf
URLDecode=URLDecode&Chr(a)
EndSelect
tl=sl
sl=InStr(sl,strIn,key,1)
Loop
URLDecode=URLDecode&Mid(strIn,tl)
Endfunction
%>
转载自:http://v1.w4s.cn/support/url-decoding-support-chinese-asp-urldecode-function.htm