What are some alternative functions or approaches to handle line breaks in PHP text processing?

When processing text in PHP, line breaks can sometimes cause issues, especially when displaying the text in HTML or other formats. One approach to handle line breaks is to replace them with HTML line break tags (<br>) so that they are displayed correctly in HTML. Another approach is to remove line breaks altogether if they are not needed in the output.

// Replace line breaks with HTML line break tags
$text = &quot;This is a text with line breaks.\nHere is the next line.&quot;;
$text = nl2br($text);
echo $text;

// Remove line breaks
$text = &quot;This is a text with line breaks.\nHere is the next line.&quot;;
$text = str_replace(array(&quot;\r&quot;, &quot;\n&quot;), &#039;&#039;, $text);
echo $text;