What is the difference between \n and \r\n in terms of line breaks and how does it affect formatting in text files?
The difference between \n and \r\n is that \n represents a line feed character, which moves the cursor to the next line, while \r\n represents a carriage return followed by a line feed, which moves the cursor to the beginning of the next line. This difference can affect formatting in text files, especially when dealing with files created on different operating systems. To ensure consistent line breaks in text files, it's important to use the appropriate line break character based on the operating system.
// Replace \n with \r\n to ensure consistent line breaks in text files
$text = str_replace("\n", "\r\n", $text);