$file = 'data.txt'; $data = "This is some data that will be appended to the file.\n"; file_put_contents($file, $data, FILE_APPEND);
$file = 'data.txt'; $data = "This is some data that will be appended using fwrite.\n"; $handle = fopen($file, 'a'); fwrite($handle, $data); fclose($handle);This code will also append the string "This is some data that will be appended using fwrite.\n" to the file called "data.txt". The package library used for these examples is the PHP Standard Library.