PHP讀取檔案_2014.5.26的總結

來源:互聯網
上載者:User

標籤:style   c   a   color   strong   檔案   

1、PHP部分檔案操作函數

  (1)  fopen 開啟檔案函數

      fopen (路徑和檔案名稱,開啟檔案);

  (2)  fread 讀取檔案內容

      fread (開啟的檔案,結束位置);

  (3)  filesize 讀取檔案大小,位元組為計量單位

      filesize (路徑和檔案名稱);

  (4)  fwrite 寫入檔案內容

      fwrite (路徑和檔案名稱,寫入的內容);

  (5)  fclose 關閉開啟的檔案

       close (路徑和檔案名稱);

  

    例:

    <?php

      $arr = array(array("新聞標題222","新聞內容222"),array("新聞標題333","新聞內容3333"));

      foreach($arr as $id=>$value){

          $fp = fopen("tmp.htm","r");

          str = fread($fp,filesize("tmp.htm"));

         fclose($fp);  

       $title = $value[0];   

          $content = $value[1];  

        $path = $id.".html";  

        $str = str_replace("{title}",$title,$str);  

          $str = str_replace("{content}",$content,$str);

          $nfp = fopen($path,"w");

        fwrite($nfp,$str);  

       fclose($nfp);

    }

?>

 

2、unlink()  rmdir() 刪除函數

    unlink() 刪除檔案函數  

        unlink(路徑和檔案名稱)

    rmdir() 刪除目錄函式

        rmdir(路徑和目錄名)

 

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.