<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                http://www.yuzhe.name/Item.asp?id=109 在瀏覽器中打開一個網址,如果網址中含中文字符時瀏覽器會自動根據當前頁面的編碼進行對就的編碼。我們大家最常見到的就是用google和百度進行搜索時,中文關鍵字就是以編碼后的形式顯示在瀏覽器的地址欄里面。 最近在做一個程序時,要用到獲取搜索引擎的關鍵字功能。在網上找了很多關鍵這樣的函數代碼,然后均不是通用的,要么只能在gb2312編碼的頁面中得到對應的url為gb2312編碼的結果,要么就是只能在utf-8的頁面中得到url編碼為utf-8的解碼。但目前主流搜索引擎Google和百度的編碼卻不一樣。 Google采用了utf-8國際編碼,而百度卻用的是gb2312編碼。比如我們在google和百度搜索“雨哲”,編碼后的url路徑為: ~~~ Google:http://www.google.cn/search?q=%E9%9B%A8%E5%93%B2 百度:http://www.baidu.com/s?wd=%D3%EA%D5%DC ~~~ 也就是說: ~~~ “雨哲”的UTF-8編碼為:%E9%9B%A8%E5%93%B2 “雨哲”的GB2312編碼為:%D3%EA%D5%DC ~~~ 網上有很多url編碼解碼的函數,但均只能在單一頁面對對應的編碼進行解碼,我這篇文章說的重點就在這里:如何在一種編碼的頁面中能通時對中文進行兩種編碼的編碼,而且也能同時對兩種編碼進行對就的解碼。(注:以下所說的代碼如未作特別說明,均指在utf-8頁面環境中使用) 一、Url編碼通用代碼: ~~~ '================================================== '函 數 名: YuZhe_UrlEncode '功 能: 將指定字符進行指定格式進行編碼 '參 數: iStrCode 目標字符 ' iPageCode 指定編碼 65001-UTF-8或936-GB2312 '================================================== Function YuZhe_UrlEncode(iStrCode, iPageCode) Dim StrUrlEncode StrUrlEncode = "" '初始化變量 If iPageCode <> SetPageCode Then '如果指定要編碼的類型與當前頁面編碼不一至,則臨時設置處理該函數時的頁面編碼類型 Session.CodePage = iPageCode StrUrlEncode = Server.UrlEncode(iStrCode) Session.CodePage = SetPageCode '還原頁面編碼為默認 Else StrUrlEncode = Server.UrlEncode(iStrCode) End If YuZhe_UrlEncode = StrUrlEncode End Function ~~~ 示例: ~~~ <% Const SetPageCode = "UTF-8" '定義當前文件編碼類型 Response.Write "輸出UTF-8編碼" & YuZhe_UrlEncode("雨哲", 65001) Response.Write "輸出GB2312編碼" & YuZhe_UrlEncode("雨哲", 936) %> ~~~ 二、URl解碼函數: 1.UTF-8解碼函數: ~~~ '================================================== '函數名: UTF2GB '功能: 將utf-8編碼解碼為中文 'UTFStr: 需要編碼的字符,在utf-8和gb2312兩種頁面編碼中均可使用 '================================================== function UTF2GB(UTFStr) Dim dig,GBSTR for Dig=1 to len(UTFStr) if mid(UTFStr,Dig,1)="%" then 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) dim a,i,j,DigS,Unicode 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 c16to2(x) '這個函數是用來轉換16進制到2進制的,可以是任何長度的,一般轉換UTF-8的時候是兩個長度,比如A9 '比如:輸入“C2”,轉化成“11000010”,其中1100是"c"是10進制的12(1100),那么2(10)不足4位要補齊成(0010)。 dim tempstr dim i: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'如果不足4位那么補齊4位數 loop c16to2=c16to2 & tempstr next end function function c2to16(x) '2進制到16進制的轉換,每4個0或1轉換成一個16進制字母,輸入長度當然不可能不是4的倍數了 dim i:i=1'臨時的指針 for i=1 to len(x) step 4 c2to16=c2to16 & hex(c2to10(mid(x,i,4))) next end function function c2to10(x) '單純的2進制到10進制的轉換,不考慮轉16進制所需要的4位前零補齊。 '因為這個函數很有用!以后也會用到,做過通訊和硬件的人應該知道。 '這里用字符串代表二進制 c2to10=0 if x="0" then exit function'如果是0的話直接得0就完事 dim i:i=0'臨時的指針 for i= 0 to len(x) -1'否則利用8421碼計算,這個從我最開始學計算機的時候就會,好懷念當初教我們的謝道建老先生啊! if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i) next end function function c10to2(x) '10進制到2進制的轉換 dim sign, result result = "" '符號 sign = sgn(x) x = abs(x) if x = 0 then c10to2 = 0 exit function end if do until x = "0" result = result & (x mod 2) x = x \ 2 loop result = strReverse(result) if sign = -1 then c10to2 = "-" & result else c10to2 = result end if end function '雨哲注:本函數代碼來自網絡 ~~~ 示例: ~~~ <% Response.Write "解碼%E9%9B%A8%E5%93%B2" & UTF2GB("%E9%9B%A8%E5%93%B2") %> ~~~ 2.GB2312解碼函數: ~~~ '================================================== '函數名: Gb2312UrlDecode '功能: 將Gb2312Url編碼解碼為中文 'EncodeStr: 需要解碼的GB2312編碼,僅在GB2312頁面編碼中有效 '================================================== Function Gb2312UrlDecode(DecodeStr) 'On Error Resume Next If DecodeStr = "" Or IsNull(DecodeStr) Then Exit Function Dim NewGb2312UrlDecodeStr,HaveGb2312UrlDecodeChar,LastGb2312UrlDecodeChar Dim iGb2312UrlDecode,Gb2312UrlDecodeChar_C,Gb2312UrlDecodeChar_C_1,Gb2312UrlDecodeChar_Num_1 NewGb2312UrlDecodeStr = "" HaveGb2312UrlDecodeChar = False LastGb2312UrlDecodeChar = "" For iGb2312UrlDecode = 1 To Len(DecodeStr) Gb2312UrlDecodeChar_C = mid(DecodeStr,iGb2312UrlDecode,1) If Gb2312UrlDecodeChar_C = "+" Then NewGb2312UrlDecodeStr = NewGb2312UrlDecodeStr & " " ElseIf Gb2312UrlDecodeChar_C = "%" Then Gb2312UrlDecodeChar_C_1 = Mid(DecodeStr,iGb2312UrlDecode+1,2) Gb2312UrlDecodeChar_Num_1 = Cint("&H" & Gb2312UrlDecodeChar_C_1) If HaveGb2312UrlDecodeChar Then HaveGb2312UrlDecodeChar = False NewGb2312UrlDecodeStr = NewGb2312UrlDecodeStr & Chr(Cint("&H" & LastGb2312UrlDecodeChar & Gb2312UrlDecodeChar_C_1)) Else If abs(Gb2312UrlDecodeChar_Num_1) <= 127 then NewGb2312UrlDecodeStr = NewGb231 HaveGb2312UrlDecodeChar = True LastGb2312UrlDecodeChar = Gb2312UrlDecodeChar_C_1 End If End if iGb2312UrlDecode = iGb2312UrlDecode+2 Else NewGb2312UrlDecodeStr = NewGb2312UrlDecodeStr & Gb2312UrlDecodeChar_C End If Next Gb2312UrlDecode = NewGb2312UrlDecodeStr End Function ~~~ 示例: ~~~ <% Const SetPageCode = "65001" '定義當前文件編碼類型 If SetPageCode <> 936 Then Session.CodePage = 936 Response.Write "%D3%EA%D5%DC解碼結果" & Gb2312UrlDecode("%D3%EA%D5%DC") Session.CodePage = SetPageCode Else Response.Write "%D3%EA%D5%DC解碼結果" & Gb2312UrlDecode("%D3%EA%D5%DC") End If %> ~~~ 版權申明:轉載請注明來源“雨哲在線”。本信息與以上內容是不可分割的。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看