How can the fopen function be used to prevent overwriting the original first line in a file when writing new entries in PHP?

When using the fopen function in PHP to write to a file, specifying the 'a' mode (append) instead of 'w' mode (write) will prevent overwriting the original content. This way, new entries will be added to the end of the file without affecting the existing data.

$file = 'example.txt';
$newEntry = "New entry to add to the file\n";

$handle = fopen($file, 'a');
fwrite($handle, $newEntry);
fclose($handle);