一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

gb2312 utf-8乱码与URL中文解码

时间:2010-12-23 编辑:简简单单 来源:一聚教程网

<%
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 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%>




page(gb2312)-111com.net





<%
response.write(request.querystring("keyword"))
%>


uft-8

 

<%@language="vbscript" codepage="65001"%>
<%session.codepage=65001%>




page(utf-8)-111com.net





<%
response.write(request.querystring("keyword"))
%>

热门栏目