Hàm đặt thuộc tính nofollow cho external link
Hôm nay LAMWEBVIET giới thiệu tới các bạn 1 hàm để tự động tìm và chèn thuộc tính nofollow vào các link ngoại (external link) ở bài viết nên cho bạn nào cần
function nofollow($content) {
preg_match_all('~~isU',$content,$matches);
for ( $i = 0; $i <= sizeof($matches[0]); $i++){
if ( !preg_match( '~nofollow~is',$matches[0][$i])
&& !preg_match( '~'.$url.'~',$matches[0][$i]) ){
$result = trim($matches[0][$i],">");
$result .= ' rel="nofollow">';
$content = str_replace($matches[0][$i], $result, $content);
}
}
return $content;
}
Các bạn thay gán giá trị cho biến $url là link của website của các bạn nhé
Chúc các bạn thành công