PHP PHP Regular Expression Filter for URL Detection and Hyperlink Creation
Learn how to use PHP regular expressions to detect URLs in text and create hyperlinks for them.
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$text = "The text you want to filter goes here. http://www.google.com/";
if (preg_match($reg_exUrl, $text, $url)) {
echo preg_replace($reg_exUrl, "<a href=" . $url[0] . ">.$url[0].</a>", $text);
} else {
echo $text;
}