How can the code provided be improved to ensure proper line breaks are inserted in the text file?
The issue with the current code is that it is not inserting proper line breaks in the text file when writing the content. To ensure proper line breaks are inserted, we can use the PHP_EOL constant which represents the correct end-of-line character for the operating system. By appending PHP_EOL to each line of text before writing it to the file, we can ensure that the text file will have consistent line breaks across different systems.
<?php
$file = 'example.txt';
$content = "Line 1\nLine 2\nLine 3";
$handle = fopen($file, 'w');
fwrite($handle, $content . PHP_EOL);
fclose($handle);
?>