Jump to content

turn url into real url


Vivid Lust

Recommended Posts

$str= preg_replace("/([^A-z0-9])(http|ftp|https)([\:\/\/])([^\\s]+)/","<a href=\"$2$3$4\">$2$3$4</a>",$str);

 

From http://codingforums.com/showthread.php?t=181757

 

Also was discussed previously in the regex forum at http://www.phpfreaks.com/forums/index.php/topic,287639.0.html. Please review the proper sections and search for your answer before posting, as chances are it has been answered many times before.

It's not working in my case...

 

I've a function that takes some text in the field an converts that into url if it's present....however,it displays the whole text and url as an hyperlink...and when clicked on text it displays page doesn't exist,which it is supposed to display...

 

function make_url_link($url)

{

if(empty($url)) {

        return;

    }

$url= preg_replace("/([^A-z0-9])(http|ftp|https)([\:\/\/])([^\\s]+)/","<a href=\"$2$3$4\">$2$3$4</a>",$url);

    return '<a href="'.$url.'">'.$url.'</a>';

}

 

 

Any suggestions???

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.