Append data in new line php

A simple one!

In PHP, you can append data to a file in a new line using the file_put_contents() function or the fopen() and fwrite() functions.

Method 1: Using file_put_contents()

$data = "New data to append\n";
file_put_contents('file.txt', $data, FILE_APPEND);

The FILE_APPEND flag tells file_put_contents() to append the data to the end of the file instead of overwriting it.

Method 2: Using fopen() and fwrite()

$data = "New data to append\n";
$fp = fopen('file.txt', 'a');
fwrite($fp, $data);
fclose($fp);

The 'a' mode opens the file in append mode, which means that any writes will be added to the end of the file.

In both cases, make sure to replace 'file.txt' with the actual path and name of the file you want to append to.

If you want to append data to a file in a specific format, such as CSV or JSON, you'll need to use a more sophisticated approach. Let me know if you need help with that!