Bonjour,
J'ai une fonction d'extraction de données sur des pages web qui ne renvoie plus rien quand elle est appelée dans une boucle while .
Avec l'URL dans une variable OK

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function extraction($string, $start, $end)
{
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three);
return $unit;
}
///////////////////////////////
function url($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT,'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scrap_time = curl_exec($ch);
curl_close($ch);
$text = $curl_scrap_time;
$start0 = '<table class="infobox_v2">';
$end0 = '</table>';
$unit0 = extraction($text, $start0, $end0);
return $unit0;
}  
///////////////////////////////
 
  $page_suivante = "https://fr.wikipedia.org/wiki/Pont_Yavuz_Sultan_Selim";
 
  echo url($page_suivante);
Par l'intermédiaire d'une boucle while plus aucune sortie

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
function extraction($string, $start, $end)
{
$pos = stripos($string, $start);
$str = substr($string, $pos);
$str_two = substr($str, strlen($start));
$second_pos = stripos($str_two, $end);
$str_three = substr($str_two, 0, $second_pos);
$unit = trim($str_three);
return $unit;
}
///////////////////////////////
function url($url)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERAGENT,'Googlebot/2.1 (+http://www.google.com/bot.html)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curl_scrap_time = curl_exec($ch);
curl_close($ch);
$text = $curl_scrap_time;
$start0 = '<table class="infobox_v2">';
$end0 = '</table>';
$unit0 = extraction($text, $start0, $end0);
return $unit0;
}  
//////////////////////////////////////////////
if (!$fp = fopen("liens_a_suivre","r")) {
echo "Echec de l'ouverture du fichier";
exit;
}
else {
 while(!feof($fp)) {
  $Ligne = fgets($fp,255);
  echo url($Ligne);
 }
 fclose($fp); 
}
Dans le fichier "liens_a_suivre" exemple :

Je sèche grave, merci par avance pour votre bienveillance à l'égard d'un néophyte en PHP.
Cordialement