What are some potential pitfalls when using PHP to replace line breaks with <br> tags in HTML strings?
One potential pitfall when using PHP to replace line breaks with <br> tags in HTML strings is that it may not account for different line break characters used in different operating systems (e.g., \n for Unix-based systems and \r\n for Windows). To solve this issue, you can use the PHP function nl2br(), which automatically converts newline characters to <br> tags while handling different line break formats.
<?php
$htmlString = "This is a text with \n line breaks.";
echo nl2br($htmlString);
?>