How to make anchor link of the urls in the text in php - OneNightStudy.Com

Thursday, 21 September 2017

How to make anchor link of the urls in the text in php

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);


2 comments:

  1. https://i.ytimg.com/vi/Ly7caqwcFto/maxresdefault.jpg

    ReplyDelete
    Replies
    1. http://poster.keepcalmandposters.com/2476345.png

      Delete