I have tried following so far:
<?php
// The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
$text = "The text I want to filter is here. It has urls http://www.example.com and http://www.example.org";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
// make the urls hyper links
$final = preg_replace($reg_exUrl, "<a href=\"{$url[0]}\">{$url[0]}</a> ", $text);
echo $final;
} else {
// if no urls in the text just return the text
echo $text;
}
The only issue I am facing is that this is replacing both the URL's with the same url(that is the one found first). How do I loop this to replace each url with their own?