What function can I use to achieve automatic line breaks in PHP?

To achieve automatic line breaks in PHP, you can use the nl2br() function. This function inserts HTML line breaks (<br>) before all newlines in a string, making it display properly in HTML.

$text = &quot;This is a text with \n line breaks.&quot;;
echo nl2br($text);