I had a function that detected URLs in text and turned them into links. However it won't take user directly to the link but rather to a warning page that it was an outside link. It worked well.
I have modified this function since to check if the URL was to an internal page within my site. I added preg_replace_callback and piped the match into another function that created links based on a logic mySite vs. Outside Site.
I have broke something because the function just doesn't work any longer. Since i can't seem to be able to see what I messed up, could someone please take a look at the new function below...
function makeLink($src) {
$checkDomain = preg_replace_callback('/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/', 'checkDomain', $src);
function checkDomain($matches) {
$host = parse_url($matches[0], PHP_URL_HOST);
$host = ltrim($host, 'www.');
if ($host == 'mydomain.com') {
$makeUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3">$2$4</a>', $matches[0]);
} else {
$makeUrl = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="/warningPage/$2$3" rel="nofollow">$2$4</a>', $matches[0]);
}
}
return $makeUrl;
}