I using the following to convert urls in a body of text to a hyperlink when displayed on the page. Problem is sometimes when a url is entered it will have a <br> after it iinstead of a space because the user hit return in the textbox when entering their message after the url causing the hyperlink to not work properly
$msg = preg_replace("/\b((http(s?):\/\/)|(www\.))([\w\.]+)([\/\w+\.]+.)+\w/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $msg);
It is set to stop when it hits a space at the moment but how do i make it read everything before a space and a <