A Function Called file_append_contents()¶
<?php
// appends the text to the end of the end of the file
file_put_contents($file, $text, FILE_APPEND);
// appends the text to the end of the end of the file
$fp = fwrite($file, 'a');
fwrite($fp, $text);
file_put_contents() can append data to the end of the file, with the FILE_APPEND option.
file_put_contents() keeps the file opened as little as possible, and the operation is atomic. It is better then overwriting the whole file; and it is often better than fopen(), which keeps the file open until the end of the execution.
See Also¶
PHP Features¶
Last updated: 14 July 2026