程序代码
function urldecode(encodestr)
Dim newstr,havechar,lastchar,i,char_c,next_1_c,next_1_Num
newstr=""
havechar=false
lastchar=""
for i=1 to len(encodestr)
char_c=mid(encodestr,i,1)
if char_c="+" then
newstr=newstr & " "
elseif char_c="%" then
next_1_c=mid(encodestr,i+1,2)
next_1_num=cint("&H" & next_1_c)
if havechar then
havechar=false
newstr=newstr & chr(cint("&H" & lastchar & next_1_c))
else
if abs(next_1_num)<=127 then
newstr=newstr & chr(next_1_num)
else
havechar=true
lastchar=next_1_c
end if
end if
i=i+2
else
newstr=newstr & char_c
end if
next
urldecode=newstr
end function作者: superadmin 时间: 2008-6-20 14:09
我是在开发中发现使用伪静态开发站内搜索引擎,get方式传递keywords的时候,汉字会经过url编码处理,比如在百度中搜索“百度”的时候得到的连接是:http://www.baidu.com/s?wd=%B0%D9%B6%C8&cl=3 其中%B0%D9%B6%C8就是这两个汉字的编码,而这样的文字是无法在数据库搜索出结果的,只有解码之后才可以,在这个时候就需要一个解码的函数,也就是上文中的函数。封装成函数后使用起来就很方便了:
Dim key
key=request.form("keywords")
key=urldecode(key)