What best practices can be implemented in PHP to ensure consistent handling of line breaks in text files across different operating systems?

In order to ensure consistent handling of line breaks in text files across different operating systems, it is recommended to use the PHP_EOL constant instead of hardcoding specific line break characters (\n for Unix, \r\n for Windows). This constant represents the correct line break sequence for the current operating system and helps maintain portability.

// Use PHP_EOL constant to ensure consistent line breaks
$fileContent = "This is a line of text" . PHP_EOL;
$fileContent .= "This is another line of text" . PHP_EOL;

// Write content to a file
$file = fopen('example.txt', 'w');
fwrite($file, $fileContent);
fclose($file);