What is the significance of using "\r\n" instead of just "\n" for line breaks in PHP when creating text files for download?

When creating text files for download in PHP, using "\r\n" instead of just "\n" is significant because it ensures cross-platform compatibility for line breaks. "\r\n" represents a carriage return followed by a line feed, which is the standard line ending sequence for text files in Windows. Using just "\n" may not display the line breaks correctly on Windows systems.

<?php
// Create a text file with proper line breaks for Windows
$fileContent = "Line 1\r\nLine 2\r\nLine 3";
$fileName = "example.txt";

header('Content-Type: text/plain');
header('Content-Disposition: attachment; filename="' . $fileName . '"');

echo $fileContent;
?>