What is the purpose of using constants like PHP_EOL for newline characters in PHP code?

Using constants like PHP_EOL for newline characters in PHP code helps to ensure cross-platform compatibility when dealing with line breaks. Different operating systems use different characters to represent a newline (e.g., \n for Unix/Linux, \r\n for Windows). By using PHP_EOL, your code will automatically use the correct newline character based on the platform it is running on, making your code more portable and avoiding potential formatting issues.

// Using PHP_EOL to add a newline after each line of text
$text = "Hello" . PHP_EOL . "World";
echo $text;