$string = preg_replace("/$/", "<br>", $string); // Get rid of any newline characters in $string. $string = preg_replace("/\n/", "", $string);