Jump to content

Displaying hyperlinks...


markvaughn2006

Recommended Posts

Just found this at the preg_replace man.

 

function clickable($url){
        $in=array(
        '`((?:https?|ftp)://\S+[[:alnum:]]/?)`si',
        '`((?<!//)(www\.\S+[[:alnum:]]/?))`si'
        );
        $out=array(
        '<a href="$1"  rel=nofollow>$1</a> ',
        '<a href="http://$1" rel=\'nofollow\'>$1</a>'
        );
        return preg_replace($in,$out,$url);
    }

 

May be what you are looking for.

Ok, just gotta post this, this has got to be the easiest least frustrating way to do this..

<?php  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;  }

 

much easier than i expected!

sorry .... here it is

<?php  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;  }?>

 

to use - echo makeClickableLinks($text);

 

messy but you can figure it out

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.