Hello,
I have a piece of code to find and make a hyperlinks in the article text. I use following pattern and replace. The replace text also gets rid of long hyperlinks and shorten them, putting few dots in the middle. I found this script somewhere, but don't understant it 100%. 🙂
function FindUrl($text) {
$pattern = "#(http://|HTTP://|ftp://|(www\.))([\w\-]*\.[\w\-\.]*([/?][^\s]*)?)#e";
$replace = "'<a href=\"'.('\\1'=='www.'?'http://':'\\1').'\\2\\3\" target=\"_blank\">'.((strlen('\\1\\2\\3')>55)?(('\\1'=='www.' ? substr('\\2\\3',0,40) : ( '\\1'=='HTTP://' ? 'http://'.substr('\\2\\3',0,33) : substr('\\1\\2\\3',0,40)) ).'.....'.substr('\\1\\2\\3',(strlen('\\1\\2\\3')-10),10)) : ('\\1'=='www.' ? '\\2\\3' : ( '\\1'=='HTTP://' ? 'http://'.'\\2\\3':'\\1\\2\\3' )) ).'</a>'";
return preg_replace($pattern, $replace, $text);
}
Is it any possibility to filter out links containing my domain eg. http://mydomain.com/... or http://www.mydomain.com/... and these links make without opening new browser window, so for these ones not use target=\"_blank\" in replace string? Other links should open in the new window as now.
Thanks a lot.
AC.Metelka