Possible Duplicate:
Linkify PHP text
Hi I have a field from a database that contains http links as well as normal text.
I need to find out a way to display this information using PHP to show Text and a link when applicable.
the following is my sql query:
$sql =
"select bw_supporting_doc
from cm3rm2 with(nolock)
where number = '$id'";
the output of this sql statement is:
Please find below the link to the FSS: http://blahblack.html
I need to display the http://blahblack.html as a link at the moment it is displaying as normal text.
Thanks!
function hyperlink($text){
$text = preg_replace("#(http://)+?([.]?[a-zA-Z0-9_/-])*#", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $text);
return $text;
}
this might do the job
example usage: $str = 'this is a random string which contains a link http://www.yahoo.com'
;
echo hyperlink($str);