What are the differences between using \n, \r\n, and nl2br for formatting text in PHP?

When formatting text in PHP, \n represents a line break, \r\n represents a carriage return followed by a line break, and nl2br converts newline characters to HTML line breaks. To implement this in PHP, you can use the nl2br function to convert newline characters to HTML line breaks.

$text = "Hello\nWorld!";
echo nl2br($text);