function parseurl($url, $text, $scheme) { global $_G; if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\[\"']+/i", trim($text), $matches)) { $url = $matches[0]; $length = 65; if(strlen($url) > $length) { $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3)); } $url = nofollow($url); return '<a href="'.(substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url).'" target="_blank">'.$text.'</a>'; } else { $url = substr($url, 1); if(substr(strtolower($url), 0, 4) == 'www.') { $url = 'http://'.$url; } $url = !$scheme ? $_G['siteurl'].$url : $url; return '<a href="'.nofollow($url).'" target="_blank">'.$text.'</a>'; } } |
function nofollow($url = '') { $temp = array(); if( ! empty($url)) { $temp = parse_url($url); if(isset($temp['host']) && $temp['host'] != $_SERVER['HTTP_HOST']) { $url .= '" rel="nofollow"'; } } unset($temp); return $url; } |
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: Discuz! 帖子外鏈自動添加nofollow的方法