How can PHP be used to append new data to an existing file without deleting or modifying the existing content?
To append new data to an existing file without deleting or modifying the existing content in PHP, you can use the 'a' mode when opening the file. This mode allows you to write to the end of the file without affecting the existing content. By using this mode, you can ensure that the new data is added to the file without overwriting anything.
$file = 'existing_file.txt';
$data = "New data to append\n";
$fileHandler = fopen($file, 'a');
fwrite($fileHandler, $data);
fclose($fileHandler);
echo "Data appended successfully!";