i need to make my users aware that they are clicking an external link. I have many sorts of chats on my website and sometimes users post links, these links could be dangerous for them so i wanted to warn them before leaving the site.
For example eveonline.com uses the following on their forums: http://www.eveonline.com/externalLink.aspx?l=http://altdevblogaday.com/2011/07/11/the-hidden-evil-of-the-micro-transaction/
whenever a link shows up they see if the domain is different than eveonline.com and if it is they add the “http://www.eveonline.com/externalLink.aspx?l=” to it.
This is my makeClickableLinks function, i use it to make links clickable, i was wondering if someone could rewrite if for me to do the above + clickable as i didnt write this function since i am clueless with preg_match.
function makeClickableLinks($text)
{
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)','<a target="_blank" href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)','\\1<a target="_blank" href="http://\\2">\\2</a>', $text);
return $text;
}
the variable $text is the post of the user.
I’m no PHP wizard, but give this a try. Note that almost all of this is taken straight out of the PHP manual here.