海上月明

          editer by sun
          posts - 162, comments - 51, trackbacks - 0, articles - 8
             :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

          使用php獲取網頁內容

          Posted on 2007-02-10 23:09 pts 閱讀(5289) 評論(1)  編輯  收藏
          簡單的做法:
          <?php
          $url="http://www.aygfsteel.com/pts";
          echo file_get_contents( $url );
          ?>
          或者:
          <?
          if ($stream = fopen('http://www.sohu.com', 'r')) {
              // print all the page starting at the offset 10
              echo stream_get_contents($stream, -1, 10);
              fclose($stream);
          }

          if ($stream = fopen('http://www.sohu.net', 'r')) {
              // print the first 5 bytes
              echo stream_get_contents($stream, 5);
              fclose($stream);
          }
          ?>

          但是如果將url換成自己的bolg時,返回的中文顯示為亂碼?


          powered by performancing firefox


          評論

          # re: 使用php獲取網頁內容  回復  更多評論   

          2007-08-26 09:05 by 愚昧
          你獲取的文件編碼和你的PHP頁面的編碼不一樣當然亂碼.

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 寿光市| 唐山市| 许昌市| 樟树市| 南涧| 芮城县| 南康市| 横峰县| 嵩明县| 平安县| 台北市| 元谋县| 高州市| 巴东县| 晋江市| 金秀| 永德县| 甘肃省| 虞城县| 嫩江县| 新乐市| 天气| 云梦县| 翼城县| 望谟县| 蓬溪县| 寿宁县| 安龙县| 定州市| 钦州市| 陕西省| 文安县| 赣州市| 岑溪市| 剑河县| 治多县| 镇巴县| 宜兰县| 英超| 准格尔旗| 东乡县|