How to make anchor link of the urls in the text in php
These is the code to make the text urls to links in php:
$text =$blog->blog_description;
// Check if there is a url in the text
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
preg_match_all($reg_exUrl, $text, $matches);
$usedPatterns = array();
foreach($matches[0] as $pattern){
if(!array_key_exists($pattern, $usedPatterns)){
$usedPatterns[$pattern]=true;
$text = str_replace ($pattern, "".$pattern." ", $text);
}
}
echo nl2br($text);
https://i.ytimg.com/vi/Ly7caqwcFto/maxresdefault.jpg
ReplyDeletehttp://poster.keepcalmandposters.com/2476345.png
Delete