How can the nl2br function be removed from a PHP code to prevent unwanted formatting?

The nl2br function in PHP is used to convert newlines (\n) to HTML line breaks (<br>). If you want to prevent this unwanted formatting, you can simply remove the nl2br function from your code. This can be done by removing the function call wherever it appears in your PHP code.

// Original code with nl2br function
$text = &quot;Hello\nWorld&quot;;
echo nl2br($text);

// Code without nl2br function
$text = &quot;Hello\nWorld&quot;;
echo $text;