What function can be used in PHP to convert newline characters to <br> tags for proper display?

To convert newline characters to <br> tags in PHP for proper display, you can use the nl2br() function. This function will convert all newline characters (\n) in a string to <br> tags, allowing the text to be displayed with proper line breaks in HTML.

$text = &quot;This is a text with\nnew lines.&quot;;
echo nl2br($text);