How does nl2br() handle the conversion of "\n" to HTML line breaks in PHP and why is this conversion important for displaying user input?

nl2br() is a PHP function that converts newline characters ("\n") to HTML line breaks ("<br>"). This conversion is important for displaying user input because HTML does not recognize newline characters as line breaks, so without this conversion, any text with newline characters would be displayed as a single continuous line.

$user_input = &quot;Hello\nWorld&quot;;
$converted_input = nl2br($user_input);

echo $converted_input;