相關(guān)關(guān)鍵詞
關(guān)于我們
最新文章
- PHP中opcode緩存簡單用法分析
- thinkPHP控制器變量在模板中的顯示方法示例
- PHP move_uploaded_file() 函數(shù)(將上傳的文件移動(dòng)到新位置)
- dirname(__FILE__)的含義和應(yīng)用說明
- thinkPHP5框架實(shí)現(xiàn)分頁查詢功能的方法示例
- PHP中單雙號(hào)與變量
- PHP獲得當(dāng)日零點(diǎn)時(shí)間戳的方法分析
- Laravel ORM對(duì)Model::find方法進(jìn)行緩存示例詳解
- PHP讀寫文件高并發(fā)處理操作實(shí)例詳解
- 【CLI】利用Curl下載文件實(shí)時(shí)進(jìn)度條顯示的實(shí)現(xiàn)
增加對(duì)站點(diǎn)內(nèi)容外部鏈接的過濾
原來站內(nèi)很多文章都是摘錄的外部文章,文章里很多鏈接要么是時(shí)間久了失效了,要么就是一些測試的網(wǎng)址,如:http://localhost/ 之類的,鏈接多了的話,就形成站內(nèi)很多死鏈接,這對(duì)SEO優(yōu)化是很不利的。那么就需要對(duì)站點(diǎn)內(nèi)的內(nèi)容進(jìn)行過濾,將不是內(nèi)部鏈接的鏈接加上 rel="nofollow"屬性。
網(wǎng)上找到了wordpress的過濾外部鏈接的函數(shù),將其改一下即可使用
//外部鏈接增加nofllow $content 內(nèi)容 $domain 當(dāng)前網(wǎng)站域名
function content_nofollow($content,$domain){
preg_match_all('/href="(.*?)"/',$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,$domain)===false ) $content=str_replace('href="'.$val.'"', 'href="'.$val.'" rel="external nofollow" ',$content);
}
}
preg_match_all('/src="(.*?)"/',$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,$domain)===false ) $content=str_replace('src="'.$val.'"', 'src="'.$val.'" rel="external nofollow" ',$content);
}
}
return $content;
}
調(diào)用的時(shí)候很好調(diào)用,如下是調(diào)用演示
$a['content'] = content_nofollow($a['content'],$domain); //將文章內(nèi)容里的鏈接增加nofllow屬性
注意!過濾的域名需要是不帶“/”的,如http://www.9u769.cn
這樣才可以很好的過濾。