How can you ensure proper line breaks in a log file when using fwrite in PHP?

When using fwrite in PHP to write to a log file, you can ensure proper line breaks by appending a newline character "\n" at the end of each log message. This will create a new line for each message written to the file, making it easier to read and manage the log contents.

$logFile = 'logfile.txt';
$logMessage = 'This is a log message';

// Open the log file in append mode
$handle = fopen($logFile, 'a');

// Write the log message with a newline character
fwrite($handle, $logMessage . "\n");

// Close the file handle
fclose($handle);