What are potential pitfalls when using nl2br function in PHP to convert text to HTML?

When using the nl2br function in PHP to convert text to HTML, one potential pitfall is that it can lead to double line breaks if the input text already contains HTML line breaks. To avoid this issue, you can first strip any existing HTML line breaks before applying the nl2br function.

// Remove existing HTML line breaks before applying nl2br
$text = strip_tags($text); 
$text = nl2br($text);

echo $text;