View Full Version : makeing links clickable with PHP

11-02-2006, 10:01 PM
Hey there, I want my php code to recognise links and make them clickable automaticly. I found this scrpt that works fine:


function makeClickableLinks($text) {

$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1">\\1</a>', $text);

return $text;


// Usage

// Email address example
$text = "you@example.com";
echo makeClickableLinks($text);

echo "<br /><br />";

// URL example
$text = "http://www.example.com";
echo makeClickableLinks($text);

echo "<br /><br />";

// FTP URL example
$text = "ftp://ftp.example.com";
echo makeClickableLinks($text);


But is there a way of making it recognise google.com and www.google.com

thanks for your time.

11-02-2006, 10:07 PM
I've been trying to do this same thing,
and it seems to me that with would building some kind of array for all of the possible domain extensions that this is not possible.

example ".com,.net,.ca".. and so on.
if you had this, I don't see any reason why it shouldn't work.

I've actually been trying to find a way to make it skip links that are already "clickable" ( coming out of a large already existing data base ), but haven't had a chance to finish yet.

good luck!

11-02-2006, 10:34 PM
TY ken,

Just found some more code in the phpbb script, as its free ware it should be ok for me to use.

this lets me do www.google.com

but still stuck on google.com