How does the nl2br function in PHP handle line breaks and HTML tags conversion?

The nl2br function in PHP converts new line characters (\n) to HTML line breaks (<br>). However, it does not convert other HTML tags. To convert both new line characters and HTML tags, you can use the htmlspecialchars function in combination with nl2br.

$text = &quot;&lt;p&gt;This is a paragraph.\nThis is a new line.&lt;/p&gt;&quot;;
$converted_text = nl2br(htmlspecialchars($text));
echo $converted_text;