函数示例如下:使用方法:echo content_nofollow('HTML代码', '.apipost.cn');
则会将非apipost.cn的域名统统加上 rel=nofollow 标签。/**
* 超链添加rel="nofollow"
*
// 所有内页详情输出请使用此函数处理
*/
function content_nofollow($content, $domain){
preg_match_all('/ target="_blank" href="https://url.apipost.cn/url?%28.%2A%3F%29" rel="external nofollow" /', $content, $matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val, $domain) === false ){
$content = str_replace(' target="_blank" href="https://url.apipost.cn/url?%27+.+%24val+.+%27" rel="external nofollow" ', ' target="_blank" href="https://url.apipost.cn/url?%27+.+%24val+.+%27" rel="external nofollow" rel="external nofollow" ', $content);
}
}
}
preg_match_all('/ target="_blank" src="(.*?)" rel="external nofollow" /', $content, $matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val, $domain)===false ) {
$content = str_replace(' target="_blank" target="_blank" src="' . $val . '" rel="external nofollow" rel="external nofollow" ', ' target="_blank" target="_blank" src="' . $val . '" rel="external nofollow" rel="external nofollow" rel="external nofollow" ', $content);
}
}
}
return $content;
}