日本好好热aⅴ|国产99视频精品免费观看|日本成人aV在线|久热香蕉国产在线

  • <cite id="ikgdy"><table id="ikgdy"></table></cite>
    1. 西西軟件園多重安全檢測(cè)下載網(wǎng)站、值得信賴的軟件下載站!
      軟件
      軟件
      文章
      搜索

      首頁編程開發(fā)php教程 → php中 urlencode() 和 rawurlencode 函數(shù)詳解

      php中 urlencode() 和 rawurlencode 函數(shù)詳解

      相關(guān)軟件相關(guān)文章發(fā)表評(píng)論 來源:本站整理時(shí)間:2011/3/21 13:48:56字體大。A-A+

      作者:佚名點(diǎn)擊:101次評(píng)論:2次標(biāo)簽: URLEncode

      • 類型:瀏覽輔助大。232KB語言:中文 評(píng)分:5.0
      • 標(biāo)簽:
      立即下載

      理解URLEncode:
      URLEncode:是指針對(duì)網(wǎng)頁url中的中文字符的一種編碼轉(zhuǎn)化方式,最常見的就是Baidu、Google等搜索引擎中輸入中文查詢時(shí)候,生成經(jīng)過 Encode過的網(wǎng)頁URL。

      URLEncode的方式一般有兩種一種是傳統(tǒng)的基于GB2312的Encode(Baidu、Yisou等使用),一種是 基于UTF-8的Encode(Google,Yahoo等使用)。本工具分別實(shí)現(xiàn)兩種方式的Encode與Decode。

      中文 -> GB2312的Encode -> %D6%D0%CE%C4
      中文 -> UTF-8的Encode -> %E4%B8%AD%E6%96%87

      Html中的URLEncode:
      編碼為GB2312的html文件中,
      http://ud03.kinoko.name/中文.rar -> 瀏覽器自動(dòng)轉(zhuǎn)換為 -> http://ud03.kinoko.name/%D6%D0%CE%C4.rar
      注意:Firefox對(duì)GB2312的Encode的中文URL支持不好,因?yàn)樗J(rèn)是UTF-8編碼發(fā)送URL的,但是ftp://協(xié)議可以,我試過了.我認(rèn)為這應(yīng)該算是Firefox一個(gè)bug.

      編碼為UTF-8的html文件中,
      http://ud03.kinoko.name/中文.rar -> 瀏覽器自動(dòng)轉(zhuǎn)換為 -> http://ud03.kinoko.name/%E4%B8%AD%E6%96%87.rar

      PHP中的URLEncode:

      Php代碼  
      1. <?php   
      2. //GB2312的Encode   
      3. echo urlencode("中文-_. ")."\n"//%D6%D0%CE%C4-_.+   
      4. echo urldecode("%D6%D0%CE%C4-_. ")."\n"//中文-_.   
      5. echo rawurlencode("中文-_. ")."\n"//%D6%D0%CE%C4-_.%20   
      6. echo rawurldecode("%D6%D0%CE%C4-_. ")."\n"//中文-_.   
      7. ?>  



      除了 -_. 之外的所有非字母數(shù)字字符都將被替換成百分號(hào)(%)后跟兩位十六進(jìn)制數(shù)。
      urlencode和rawurlencode的區(qū)別:
      urlencode 將空格則編碼為加號(hào)(+)
      rawurlencode 將空格則編碼為加號(hào)(%20)

      如果要使用UTF-8的Encode,有兩種方法:
      一、將文件存為UTF-8文件,直接使用urlencode、rawurlencode即可。
      二、使用mb_convert_encoding函數(shù)。

      Php代碼  
      1. <?php   
      2. $url = 'http://ud03.kinoko.name/中文.rar';   
      3. echo urlencode(mb_convert_encoding($url'utf-8''gb2312'))."\n";   
      4. echo rawurlencode(mb_convert_encoding($url'utf-8''gb2312'))."\n";   
      5. //http%3A%2F%2Fud03.kinoko.name%2F%E4%B8%AD%E6%96%87.rar   
      6. ?>  



      實(shí)例:

      Php代碼  
      1. <?php   
      2. function parseurl($url="")   
      3. {   
      4. $url = rawurlencode(mb_convert_encoding($url'gb2312''utf-8'));   
      5. $a = array("%3A""%2F""%40");   
      6. $b = array(":""/""@");   
      7. $url = str_replace($a$b$url);   
      8. return $url;   
      9. }   
      10. $url="ftp://ud03:password@ud03.kinoko.name/中文/中文.rar";   
      11. echo parseurl($url);   
      12. //ftp://ud03:password@ud03.kinoko.name/%D6%D0%CE%C4/%D6%D0%CE%C4.rar   
      13. ?>  



      JavaScript中的URLEncode:

      %E4%B8%AD%E6%96%87-_.%20%E4%B8%AD%E6%96%87-_.%20

      encodeURI 不對(duì)下列字符進(jìn)行編碼:“:”、“/”、“;”、“?”、“@”等特殊字符。

        相關(guān)評(píng)論

        閱讀本文后您有什么感想? 已有人給出評(píng)價(jià)!

        • 8 喜歡喜歡
        • 3 頂
        • 1 難過難過
        • 5 囧
        • 3 圍觀圍觀
        • 2 無聊無聊

        熱門評(píng)論

        最新評(píng)論

        發(fā)表評(píng)論 查看所有評(píng)論(2)

        昵稱:
        表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
        字?jǐn)?shù): 0/500 (您的評(píng)論需要經(jīng)過審核才能顯示)