转换中文为unicode 转换unicode到正常文本

  • A+
所属分类:PHP编程
  1. '//转换中文unicode 
  2. function URLEncoding(vstrIn)
  3.     dim i
  4.     dim strReturn,ThisChr,innerCode,Hight8,Low8
  5.     strReturn = ""
  6.     for i = 1 to Len(vstrIn)
  7.         ThisChr = Mid(vStrIn,i,1)
  8.         If Abs(Asc(ThisChr)) < &HFF then
  9.             strReturn = strReturn & ThisChr
  10.         else
  11.             innerCode = Asc(ThisChr)
  12.             If innerCode < 0 then
  13.                 innerCode = innerCode + &H10000
  14.             end If
  15.             Hight8 = (innerCode  and &HFF00)\ &HFF
  16.             Low8 = innerCode and &HFF
  17.             strReturn = strReturn & "%" & Hex(Hight8) &  "%" & Hex(Low8)
  18.         end If
  19.     next
  20.     URLEncoding = strReturn
  21. end function
  22. '//转换unicode正常文本 
  23. function bytes2BSTR(vIn)
  24.     dim i
  25.     dim strReturn,ThisCharCode,nextCharCode
  26.     strReturn = ""
  27.     for i = 1 to LenB(vIn)
  28.         ThisCharCode = AscB(MidB(vIn,i,1))
  29.         If ThisCharCode < &H80 then
  30.             strReturn = strReturn & Chr(ThisCharCode)
  31.         else
  32.             nextCharCode = AscB(MidB(vIn,i+1,1))
  33.             strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(nextCharCode))
  34.             i = i + 1
  35.         end If
  36.     next
  37.     bytes2BSTR = strReturn
  38. end function
  39. function getText(oReq,url)
  40.     on error resume next
  41.     '//创建XMLHTTP对象     
  42.     if oReq is nothing then
  43.         set oReq    = CreateObject("MSXML2.XMLHTTP")
  44.     end if
  45.     if    not oReq is nothing then
  46.         oReq.open "get",url,false
  47.         oReq.send
  48.         if oReq.status = 200 then
  49.             getText = bytes2BSTR(oReq.responseBody)
  50.         else
  51.             getText = ""
  52.         end if
  53.     else
  54.         getText = ""
  55.     end if
  56. end function