How can fwrite be used to write to a file in PHP while ensuring each entry is on a new line?

When using fwrite in PHP to write to a file, you can ensure each entry is on a new line by appending a newline character "\n" at the end of each entry before writing it to the file. This will create a new line for each entry and maintain the readability of the file.

$data = "Entry 1\n"; // Append "\n" at the end of each entry
$file = fopen("data.txt", "a"); // Open file for writing (append mode)
fwrite($file, $data); // Write data to file
fclose($file); // Close the file