What are the differences between \n, \r\n, and \r in PHP for creating line breaks?

When creating line breaks in PHP, \n represents a newline character, \r\n represents a carriage return followed by a newline character, and \r represents a carriage return. The choice between these depends on the platform you are working on - \n is commonly used in Unix-based systems, \r\n is used in Windows-based systems, and \r is used in older Mac systems. It's important to use the appropriate line break character for the platform to ensure proper formatting of text.

// Example of using \n for line breaks in Unix-based systems
echo "Line 1\nLine 2\nLine 3";

// Example of using \r\n for line breaks in Windows-based systems
echo "Line 1\r\nLine 2\r\nLine 3";

// Example of using \r for line breaks in older Mac systems
echo "Line 1\rLine 2\rLine 3";