What are the potential pitfalls of using str_replace to handle line breaks in PHP?
Using str_replace to handle line breaks in PHP can be problematic because different operating systems use different characters to represent line breaks (e.g., \n for Unix, \r\n for Windows). This can lead to inconsistent results when using str_replace to replace line breaks. To handle this issue, it is recommended to use the PHP function nl2br(), which converts newlines to HTML line breaks <br> tags, ensuring consistent display across different platforms.
$text = "This is a text with line breaks\nlike this";
echo nl2br($text);