How can the strip slashes function be used to resolve issues with nl2br in PHP?

The issue with nl2br in PHP is that it adds <br> tags before every newline character, which can result in double line breaks when displaying the text. To resolve this issue, we can use the strip_slashes function to remove any existing slashes before applying nl2br.

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