What function can be used to convert line breaks in text to HTML line breaks in PHP?

To convert line breaks in text to HTML line breaks in PHP, you can use the nl2br() function. This function takes a string as input and converts any newline characters (\n) to HTML line breaks (<br>). This is useful when displaying text from a database or form input on a webpage, as HTML line breaks are necessary for formatting the text correctly.

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