thread434-1618095
A revived thread of a great text autolinking script by jpaide.
It supports many domains / emails and youtube links.
Now to the reason for reposting:
A recent craze of links posted on my site like are causing problems facebook and twitter links are sometimes similar. Because (i assume) the link is never ended with a domian it means the <a> tag never gets closed and therefore links all text after it in the <div> lol
The code:
$ukcc = array('.co.uk' - should I add a space into this array? but then it would get linked too?
All thoughts/comments appreciated...
- free mp3 downloads and streaming
A revived thread of a great text autolinking script by jpaide.
It supports many domains / emails and youtube links.
Now to the reason for reposting:
A recent craze of links posted on my site like are causing problems facebook and twitter links are sometimes similar. Because (i assume) the link is never ended with a domian it means the <a> tag never gets closed and therefore links all text after it in the <div> lol
The code:
Code:
/* Provide HTML for normal links */
function _linkify($text){
$text = str_replace('\"', '"', $text);
if(!preg_match('/^(src|href|data|value)/ims', $text)):
$protocols = array('http','https','ftp','file','gopher','mailto');
$_protocols = implode('|',$protocols);
//$_protocols = '('.implode('|',$protocols).')';
if(!preg_match('/^('.$_protocols.')/ims', $text)):
/* Check if the URL is an email */
if (!$this->isEmail($text)):
return '<a rel="nofollow" href="[URL unfurl="true"]http://'.$text.'"[/URL] target="_blank">'.$text.'</a>';
else:
$_text = str_replace('mailto:', '', $text);
return '<a rel="nofollow" href="mailto:'.$_text.'">'.$_text.'</a>';
endif;
else:
return '<a rel="nofollow" href="'.$text.'" target="_blank">'.$text.'</a>';
endif;
else:
return $text;
endif;
}
/**
* autolink - this little function will
* automatically hyperlink url's etc.
*/
function autolink($text,$noyt=0){
$protocols = array('http','https','ftp','file','gopher','mailto');
/* Specify the allowed domain names */
$gTLDs = array('.info','.com','.edu','.org','.net','.mil');
/* You may add quite a few others so long as they do not overlap */
$newTLDs = array('.aero', '.biz', '.coop', '.info', '.museum', '.name', '.pro');
$ukcc = array('.co.uk','.gov.uk','.ac.uk','.ltd.uk','.me.uk','.mod.uk','.net.uk','.nhs.uk','.nic.uk', '.org.uk','.parliament.uk', '.plc.uk','.police.uk','.sch.uk', '.bl.uk','.icnet.uk','.jet.uk','.nls.uk');
$others = array('.tv','.eu');
$domains = array_merge($gTLDs, $newTLDs, $ukcc, $others);
$_protocols = array_map('preg_quote', $protocols);
$_domains = array_map('preg_quote', $domains);
/* First split the non word breaks */
$pattern = '/((?<!\'|\"|=| )('.implode('|', $_protocols).')[^( |\.)])/imsu';
$replace = ' \\1';
$text = preg_replace($pattern, $replace, $text);
$pattern = '/(?<! |\/|"\'|=)([URL unfurl="true"]www\.)/ims';[/URL]
$text = preg_replace($pattern, $replace, $text);
if($noyt == 0){
/* Now to translate youtube links */
$pattern = '/\s(http\:\/\/[URL unfurl="true"]www\.youtube\.com\/watch\?v\=(\w{11}))/imse';[/URL]
$text = preg_replace($pattern, "\$this->_youTubeEmbed('\\2')", $text);
}
//preg_replace_callback($search, Array($this,"autolink"), $message);
/* Now we should have clean links, recognise links */
$pattern = '/([^(\s|\n)]*('.implode ('|', $_domains).')((\?|\/|&|#)[^(\s|\n)]*)?)/imsue';
$text = preg_replace($pattern, "\$this->_linkify('\\1')", $text);
return $text;
}
$ukcc = array('.co.uk' - should I add a space into this array? but then it would get linked too?
All thoughts/comments appreciated...
- free mp3 downloads and streaming