我需要让我的用户知道他们正在单击外部链接。我的网站上有很多类型的聊天,有时用户会发布链接,这些链接可能对他们来说很危险,所以我想在离开网站之前警告他们。
例如,eveonline.com 在其论坛上使用以下内容: http://www.eveonline.com/externalLink.aspx?l=http://altdevblogaday.com/2011/07/11/the-hidden-evil-of-the-micro-transaction/
每当出现链接时,他们都会查看该域名是否与 eveonline.com 不同,如果是,他们会在其中添加“http://www.eveonline.com/externalLink.aspx?l=”。
这是我的 makeClickableLinks 函数,我用它来使链接可点击,我想知道是否有人可以重写我是否可以执行上述+可点击操作,因为我没有编写此函数,因为我对 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;
}
变量 $text 是用户的帖子。
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.
发布评论
评论(1)
我不是 PHP 专家,但请尝试一下。请注意,几乎所有内容都直接取自 此处。
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.