What are the advantages of using nl2br over <br> tags for line breaks in PHP?

Using nl2br function in PHP is advantageous over manually inserting <br> tags for line breaks because nl2br automatically inserts HTML line breaks before all newlines in a string, making it more convenient and less error-prone. Additionally, nl2br ensures that line breaks are consistent across different platforms and browsers. This function helps maintain the readability and formatting of text when outputting it in HTML.

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