海上月明

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

          使用php獲取網頁內容

          Posted on 2007-02-10 23:09 pts 閱讀(5290) 評論(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頁面的編碼不一樣當然亂碼.

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


          網站導航:
           
          主站蜘蛛池模板: 龙门县| 法库县| 任丘市| 黔西县| 资兴市| 武义县| 尼木县| 永嘉县| 甘泉县| 嵊州市| 黄梅县| 沙河市| 梁平县| 察雅县| 岗巴县| 墨江| 交口县| 武清区| 确山县| 中江县| 安龙县| 儋州市| 宜城市| 株洲市| 南充市| 邵东县| 东乡县| 新密市| 梨树县| 肃宁县| 思茅市| 峡江县| 额尔古纳市| 金阳县| 临邑县| 五指山市| 大同县| 奉新县| 济源市| 县级市| 墨江|