虚拟主机域名注册-常见问题网络编程问题 → ASP


aspURL中有中文汉字 接收乱码的问题
作者:
function UTF2GB(UTFStr)

  for Dig=1 to len(UTFStr)
    '如果UTF8编码文字以%开头则进行转换
    if mid(UTFStr,Dig,1)="%" then
       'UTF8编码文字大于8则转换为汉字
      if len(UTFStr) >= Dig+8 then
        GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
        Dig=Dig+8
     else
       GBStr=GBStr & mid(UTFStr,Dig,1)
     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
end function

function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end function

function c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
  tempstr="0" & tempstr
  loop
  c16to2=c16to2 & tempstr
  next
  end function

  function c10to2(x)
  mysign=sgn(x)
  x=abs(x)
  digs=1
  do
  if x<2^digs then
  exit do
  else
  digs=digs+1
  end if
  loop
  tempnum=x

  i=0
  for i=digs to 1 step-1
  if tempnum>=2^(i-1) then
  tempnum=tempnum-2^(i-1)
  c10to2=c10to2 & "1"
  else
  c10to2=c10to2 & "0"
  end if
  next
  if mysign=-1 then c10to2="-" & c10to2
  end function

keywords = UTF2GB(Server.UrlEncode(Request("keyword")))
response.write keywords


来源:
阅读:946
日期:2021-09-23

推荐朋友 】 【 评论 】  【 字体: 】 
上一篇:php数组去重
下一篇:js localstorage存取与重罿
  >> 相关文章
  没有相关文章。
发表评论


点  评: 字数0
用户名:  密码:

  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款