Hey guys,
I need to convert a url within a string to be a hyperlink. I have made a function which works well except for when the url has a forward slash in it.
i.e. http://yahoo.com works fine.
but http://yahoo.com/somepage.htm would show http://yahoo.com (and then /somepage.htm not as part of the link)
Here is my function:
function makeLink ( $comment ) //if there is [url]http://[/url] or [url]www.[/url] in a string it makes it a link
{
$comment = str_replace ( "http://", "", $comment );
$comment = preg_replace ( "/[^<>\s]+(\.)(com|net|org|biz|info)/i", "<a href=\"out.php?gotoURL=\\0\" target=\"_blank\"><SPAN class=comment>\\0</SPAN></a>", $comment );
$comment = preg_replace ("/(?<!<a href=\")((http|ftp)+(target=\"_blank\")(s)?:\/\/[^<>\s]+)/i", "<a href=\"http://\\0\" target=\"_blank\">\\0</a>", $comment );
return $comment;
} // end of make link function
I have been stuck on this for days now, any help would be very much appreciated.
thanks,
gp