What is the correct method to handle line breaks in PHP when saving data to a text file?

When saving data to a text file in PHP, it is important to handle line breaks properly to ensure the formatting is maintained. One common issue is that line breaks in the data can interfere with the structure of the text file. To solve this problem, you can use the PHP function `PHP_EOL` which represents the correct end-of-line character for the current platform (e.g., `\n` for Unix-based systems and `\r\n` for Windows).

$data = "This is some data with line breaks\n";
$file = fopen("data.txt", "a");
fwrite($file, $data . PHP_EOL);
fclose($file);