What is the significance of using \r\n instead of just \n when trying to write variables on separate lines in a text file using PHP?

Using \r\n instead of just \n is significant when trying to write variables on separate lines in a text file because it ensures cross-platform compatibility. \r\n represents a line break in Windows systems, while \n represents a line break in Unix-based systems. By using \r\n, you can ensure that your text file will display correctly on both Windows and Unix-based systems.

// Open a text file for writing
$file = fopen("output.txt", "w");

// Write variables on separate lines using \r\n
fwrite($file, "Variable 1\r\n");
fwrite($file, "Variable 2\r\n");
fwrite($file, "Variable 3\r\n");

// Close the file
fclose($file);