今天遇到自己上网拼命找资料了。无数个urlencode可以供使用,还可以找到很多版本的utf-8转gb的函数。但是都不是很好用。特别在遇到中文的时候。
下面的函数该是您收藏的。
<%
-----------------------------------
'utf-8 -> gb2312
'-----------------------------------
function UTF2GB(UTFStr)
UTFStr=replace(UTFStr,"+","%20")
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if LCase(mid(UTFStr,Dig+1,1))="e" then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & chr(eval("&h"+mid(UTFStr,Dig+1,2)))
Dig=Dig+2
end if
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
next
UTF2GB=GBStr
end function
function ConvChinese(x)
A=split(mid(x,2),"%")
i=0
j=0
for i=0 to ubound(A)
A(i)=c16to2(A(i))
next
for i=0 to ubound(A)-1
DigS=instr(A(i),"0")
Unicode=""
for j=1 to DigS-1
if j=1 then
A(i)=right(A(i),len(A(i))-DigS)
Unicode=Unicode & A(i)
else
i=i+1
A(i)=right(A(i),len(A(i))-2)
Unicode=Unicode & A(i)
end if
next
if len(c2to16(Unicode))=4 then
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
else
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
end if
next
end function
function c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
next '
