<%
function urldecode(strin)
urldecode = “”
dim sl: sl = 1
dim tl: tl = 1
dim key: key = “%”
dim kl: kl = len(key)
sl = instr(sl, strin, key, 1)
do while sl>0
if (tl=1 and sl<>1) or tl<sl then
urldecode = urldecode & mid(strin, tl, sl-tl)
end if
dim hh, hi, hl
dim a
select case ucase(mid(strin, sl+kl, 1))
case “u”:’unicode urlencode
a = mid(strin, sl+kl+1, 4)
urldecode = urldecode & chrw(“&h” & a)
sl = sl + 6
case “e”:’utf-8 urlencode
hh = mid(strin, sl+kl, 2)
a = int(“&h” & hh)’ascii码
if abs(a)<128 then
sl = sl + 3
urldecode = urldecode & chr(a)
else
hi = mid(strin, sl+3+kl, 2)
hl = mid(strin, sl+6+kl, 2)
a = (“&h” & hh and &h0f) * 2 ^12 or (“&h” & hi and &h3f) * 2 ^ 6 or (“&h” & hl and &h3f)
if a<0 then a = a + 65536
urldecode = urldecode & chrw(a)
sl = sl + 9
end if
case else:’asc urlencode
hh = mid(strin, sl+kl, 2)’高位
a = int(“&h” & hh)’ascii码
if abs(a)<128 then
sl = sl + 3
else
hi = mid(strin, sl+3+kl, 2)’低位
a = int(“&h” & hh & hi)’非ascii码
sl = sl + 6
end if
urldecode = urldecode & chr(a)
end select
tl = sl
sl = instr(sl, strin, key, 1)
loop
urldecode = urldecode & mid(strin, tl)
end function
%>
下面看一款关于站点下gb2312和utf-8页面传递参数乱码的终极解决方法
ansi
<%@language="vbscript" codepage="936"%>
<%session.codepage=936%>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>page(gb2312)-111cn.net</title>
</head><body>
<script type="text/网页特效">
document.write("<a href='t2.asp教程?keyword=" + escape("木子屋") + "'>木子屋</a>");
</script>
<br/>
<%
response.write(request.querystring("keyword"))
%>
</body>
</html>
uft-8
<%@language="vbscript" codepage="65001"%>
<%session.codepage=65001%>
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>page(utf-8)-111cn.net</title>
</head><body>
<script type="text/javascript">
document.write("<a href='t1.asp?keyword=" + escape("木子屋") + "'>木子屋</a>");
</script>
<br/>
<%
response.write(request.querystring("keyword"))
%>
</body>
</html>