可以通過在fopen()
函數中使用a
或a+
模式將數據追加到檔中。 下麵來看看一個簡單的例子,將數據附加(追加)到data.txt
檔中。
讓我們先看看檔(data.txt
)中的數據。
welcome to php file write
PHP附加到檔 - fwrite()函數
PHP fwrite()
函數用於將數據寫入和追加到檔中。
示例
<?php
$fp = fopen('data.txt', 'a');//opens file in append mode
fwrite($fp, ' this is additional text ');
fwrite($fp, 'appending data');
fclose($fp);
echo "File appended successfully";
?>
執行上面代碼輸出結果(查看data.txt
檔中的內容)如下 -
welcome to php file write this is additional text appending data