markvaughn2006 Posted January 31, 2010 Share Posted January 31, 2010 sorry for being such a noob.. but how do i echo a users input and allow hyperlinking?? Right now if a person puts http://example.com somewhere in their message you can't click on it...thanks for any help Quote Link to comment Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 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. Quote Link to comment Share on other sites More sharing options...
markvaughn2006 Posted January 31, 2010 Author Share Posted January 31, 2010 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! Quote Link to comment Share on other sites More sharing options...
markvaughn2006 Posted January 31, 2010 Author Share Posted January 31, 2010 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 Quote Link to comment Share on other sites More sharing options...
premiso Posted January 31, 2010 Share Posted January 31, 2010 The problem with that function is eregi is depreciated in PHP6. It is advised to use preg functions instead, as they are not being depreciated. Quote Link to comment Share on other sites More sharing options...
cags Posted February 1, 2010 Share Posted February 1, 2010 Technically eregi is already deprecated (as of PHP 5.3) and will be removed as of PHP 6.0, but premisos' point still holds true. That being said it wouldn't take much to convert it to use preg_replace. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.