How can you detect and replace line breaks in a string without using nl2br() in PHP?

To detect and replace line breaks in a string without using nl2br() in PHP, you can use the PHP function str_replace(). This function allows you to search for a specific string (such as "\n" for line breaks) and replace it with another string (such as "<br>"). By using str_replace() in conjunction with the PHP function nl2br(), you can effectively replace line breaks in a string without using nl2br().

&lt;?php
$string = &quot;Hello\nWorld!&quot;;
$replaced_string = str_replace(&quot;\n&quot;, &quot;&lt;br&gt;&quot;, $string);
echo $replaced_string;
?&gt;