Well, this lively discussion resulted in no solutions so far...
So, going back to where I started. This function will convert text that looks like URl into links. If user enabled option to bypass alert the link will take them directly to the destination. I set that preference in cookie.
What I need now is to modify the second part. If the link is within my domain it should be a simple link but if it is to an external page, I need to send user to a warning page first.
// alert about external link
function url2link($extUrlStr) {
// if cookie set -- bypass alert screen and take directly to the external page
if ($_COOKIE['externalLink'] == $_SESSION['member_id']) {
$setUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" rel="nofollow" target="_blank">$2$4</a>', $extUrlStr);
} else {
// here I need to be able to detect whether a link is internal or external
// There might be multiple links in the text... need some sort of loop mechanism.
// STUCK!!!
if ($myLink == 'internal') {
$setUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" rel="nofollow" target="_blank">$2$4</a>', $extUrlStr);
} else {
$setUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="/link/$2$3" rel="nofollow">$2$4</a>', $extUrlStr);
}
}
return $setUrl;
}
}