Code:
<?php
$str = "bla http://www.example.com bla bla http://www.example.net bla bla";
$m = preg_match_all('/http:\/\/[a-z0-9A-Z.]+(?(?=[\/])(.*))/', $str, $match);
if ($m) {
$links = $match[0];
for ($j = 0; $j < $m; $j++) {
$str = str_replace($links[$j],
'<a href="'.$links[$j].'">'.$links[$j].'</a>',
$str);
}
}
echo "Content: ".$str;
?>
Output:
Refer:
http://php.net/manual/en/function.preg-match-all.php
http://php.net/manual/en/function.preg-match.php
Other regex expressions to match URL format:
@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@