What are the different ways to encode a line break in PHP?

In PHP, there are different ways to encode a line break depending on the context in which it is needed. One common way is to use the "\n" character to represent a line break in a string. Another method is to use the PHP_EOL constant, which represents the correct end-of-line character for the current platform. Additionally, the nl2br() function can be used to insert HTML line breaks (<br>) before all newlines in a string.

// Using &quot;\n&quot; to encode a line break
$text_with_line_break = &quot;This is line 1.\nThis is line 2.&quot;;

// Using PHP_EOL constant to encode a line break
$text_with_line_break = &quot;This is line 1.&quot; . PHP_EOL . &quot;This is line 2.&quot;;

// Using nl2br() function to insert HTML line breaks
$text_with_line_break = &quot;This is line 1.\nThis is line 2.&quot;;
echo nl2br($text_with_line_break);