PHP 檔案寫入或追加資料

2022-07-06 21:30:11 字數 886 閱讀 8671

php file_put_contents() 函式是一次性向檔案寫入字串或追加字串內容的最合適選擇。

file_put_contents() 函式用於把字串寫入檔案,成功返回寫入到檔案內資料的位元組數,失敗則返回 false。

語法:

int file_put_contents ( string filename, string data [, int flags [, resource context]] )
引數說明:

引數說明

filename

要寫入資料的檔名

data

要寫入的資料。型別可以是 string,array(但不能為多維陣列),或者是 stream 資源

flags

可選,規定如何開啟/寫入檔案。可能的值:file_use_include_path:檢查 filename 副本的內建路徑

lock_ex:對檔案上鎖

context

可選,context是一組選項,可以通過它修改文字屬性

例子:

<?php

echo file_put_contents("test.txt", "this is something.");

?>

執行該例子,瀏覽器輸出:

18
而 test.txt 檔案(與程式同目錄下)內容則為:this is something.。

<?php

?>

執行程式後,test.txt 檔案內容變為:this is something.this is another something.

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

iOS plist檔案追加資料

我在對resources rchd rchd.plist內容進行操作.想在plist檔案裡面追加一條資料.我現在的 如下 dictionary nsmutabledictionary alloc initwithcontentsoffile path 然後就是把要新增的資料放入到dictionary...

handsontable 追加資料

之後決定選擇其他的框架來做 搜尋發現 handsontable 比較合適,追加資料時渲染速度很快,追加 500條資料用時在 200ms 之內。handsontable 的官網 handsontable 追加資料主要使用的方法是 getsourcedata 下面附上測試 testhandsontabl...

PHP合併和追加陣列

合併陣列 array merge 函式將陣列合併到一起,返回乙個聯合的陣列。所得到的陣列以第乙個輸入陣列引數開始,按後面陣列引數出現的順序依次迫加。其形式為 1arrayarray merge arrayarray1 array2 arrayn 這個函式將乙個或多個陣列的單元合併起來,乙個陣列中的值...