php實現以唯讀方式開啟檔案的方法,_PHP教程

來源:互聯網
上載者:User

php實現以唯讀方式開啟檔案的方法,


本文執行個體講述了php實現以唯讀方式開啟檔案的方法。分享給大家供大家參考。具體分析如下:

php中可以通過fopen()開啟一個檔案,第二個參數設定為"r"表示已唯讀方式開啟,函數返回一個檔案控制代碼,其它函數就可以通過這個檔案控制代碼對檔案進行不同方式的讀取

<?php $file = fopen("/tmp/file.txt", "r");print("Type of file handle: " . gettype($file) . "\n");print("The first line from the file handle: " . fgets($file));fclose($file); ?>

上面的代碼返回如下結果

Type of file handle: resource
The first line from the file handle: Welcome to sharejs.com php tutorials

檔案讀取完成後,需要使用fclose()函數關閉檔案控制代碼,以釋放資源

希望本文所述對大家的php程式設計有所協助。

http://www.bkjia.com/PHPjc/968255.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/968255.htmlTechArticlephp實現以唯讀方式開啟檔案的方法, 本文執行個體講述了php實現以唯讀方式開啟檔案的方法。分享給大家供大家參考。具體分析如下: php中可...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.