Aggiungere nofollow link a tutti link presenti in una pagina
Posted on 05. Mar, 2009 by Administrator in php, tutorials
ob_start();
// Your sites code goes here
$content = ob_get_contents();
@ob_end_clean();
preg_match_all(’!href[\s]*=[\s]*["\']{1}([\w]+?://[\w#$%&~/.\-;:=,?@\[\]+]*)["\']{1}!’,$content,$matches);
// Replace all outbound links with nofollow
$replaced = array();
for($i=0;$i
if(strstr($matches[1][$i],’http://www.sitename.com’)) continue;
if(strstr($matches[1][$i],’http://sitename.com’)) continue;
if(in_array($matches[0][$i],$replaced))continue;
$content = str_replace($matches[0][$i],$matches[0][$i].’ rel=”nofollow”‘,$content);
$replaced[] = $matches[0][$i];
}
echo $content;




One Comment
labo
30. Apr, 2009
visto che copi i codici da altri siti, almeno fallo bene. mancano dei pezzi…
a chi interessasse il codice (e l’autore) originale si può trovare qua http://www.ngcoders.com/tag/regexp-url-matching
Leave a reply