Classe affiche les élements d'un tableau

Fermé
amdnibrass Messages postés 23 Date d'inscription mercredi 2 octobre 2013 Statut Membre Dernière intervention 28 juillet 2015 - Modifié par jordane45 le 26/07/2015 à 18:57
miramaze Messages postés 1429 Date d'inscription mercredi 29 juillet 2009 Statut Contributeur Dernière intervention 1 mai 2022 - 26 juil. 2015 à 12:41
Bonjour,
j'écrit ce script pour m'afficher les liens internes d'un sites web mais il ne retourne rien

<?php 

// It may take a whils to crawl a site ... 
set_time_limit(10000); 

// Inculde the phpcrawl-mainclass 
include_once('../PHPCrawl_083/PHPCrawl_083/libs/PHPCrawler.class.php');  

// Extend the class and override the handleDocumentInfo()-method 
$tab = array(); 
class MyCrawler extends PHPCrawler  
{ 
  function handleDocumentInfo(PHPCrawlerDocumentInfo $DocInfo)  
  { 
    // Just detect linebreak for output ("\n" in CLI-mode, otherwise "<br>"). 
 global $tab;
    if (PHP_SAPI == "cli") $lb = "\n"; 
    else $lb = "<br />"; 

    // Print the URL and the HTTP-status-Code 
 if(!in_array($DocInfo->url,$tab,true)){
    array_push($tab,$DocInfo->url);
    
    }
     
     
     
     
    echo $lb; 
     
    flush(); 
  }  
} 

// Now, create a instance of your class, define the behaviour 
// of the crawler (see class-reference for more options and details) 
// and start the crawling-process.  

$crawler = new MyCrawler(); 

// URL to crawl 
$crawler->setURL("[http://www.tunisie-web.org] "); 

// Only receive content of files with content-type "text/html" 
$crawler->addContentTypeReceiveRule("#text/html#"); 

// Ignore links to pictures, dont even request pictures 
$crawler->addURLFilterRule("#\.(jpg|jpeg|gif|png)$# i"); 

// Store and send cookie-data like a browser does 
$crawler->enableCookieHandling(true); 

// Set the traffic-limit to 1 MB (in bytes, 
// for testing we dont want to "suck" the whole site) 
$crawler->setTrafficLimit(1000 * 1024); 
$crawler->go(); 
foreach ($tab as $link ){
echo $link ; 
}
?>


je pense que l'erreur au niveau de declaration du tableau
aide svp !


EDIT : Ajout du langage dans les balises de code

1 réponse

miramaze Messages postés 1429 Date d'inscription mercredi 29 juillet 2009 Statut Contributeur Dernière intervention 1 mai 2022 92
Modifié par miramaze le 26/07/2015 à 12:41
Hello,
ça fonctionne chez moi, cette ligne ne fait qu'afficher un saut de ligne
echo $lb; 
tu peux la virer.
0