What are common issues when writing data to a text file with PHP and creating line breaks?

When writing data to a text file with PHP and creating line breaks, a common issue is not properly formatting the line breaks. To ensure line breaks are correctly inserted, you can use the PHP_EOL constant which represents the correct end of line character for the current platform. This will ensure that line breaks are inserted correctly regardless of the operating system.

$data = "Line 1" . PHP_EOL . "Line 2" . PHP_EOL . "Line 3";
$file = fopen("data.txt", "w");
fwrite($file, $data);
fclose($file);