PHP內建函數file_put_content(),將資料寫入檔案,使用FILE_APPEND 參數進行內容追加

來源:互聯網
上載者:User

標籤:

file_put_contents(fileName,data,flags,context)

入參說明:

參數 說明
fileName 要寫入資料的檔案名稱
data 要寫入的資料。類型可以是 string,array(但不能為多維陣列),或者是 stream 資源
flags 可選,規定如何開啟/寫入檔案。可能的值:
  1. FILE_USE_INCLUDE_PATH:檢查 filename 副本的內建路徑
  2. FILE_APPEND:在檔案末尾以追加的方式寫入資料
  3. LOCK_EX:對檔案上鎖
context 可選,Context是一組選項,可以通過它修改文字屬性

 

 

 

 

 

 

 

file_put_contents預設的是重新寫檔案,會替換原先的值。當設定 flags 參數值為 FILE_APPEND 時,表示在已有檔案內容後面追加內容的方式寫入新資料。

file_put_contents() 的行為實際上等於依次調用 fopen(),fwrite() 以及 fclose() 功能一樣。

eg.

<?php

file_put_contents("result.txt", "hello", FILE_APPEND);

file_put_contents("result.txt", "world", FILE_APPEND);
?>

PHP內建函數file_put_content(),將資料寫入檔案,使用FILE_APPEND 參數進行內容追加

聯繫我們

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