Jump to content

Last Try (Desperate) - Please help with foreach loop error handling


phoenixx

Recommended Posts

I just need to stop the file using break.. NOT die().... if the foreach has reached the end of the data and produces an error.  Hope you can help me.  Here's the code.  And thanks to those who try.

 

<?
// Let's Extract Page Links
$k = (1);
$v = (1);
$loopcount=(0);
WHILE (($k > '') || ($v > '')){
	if ($d < ''){
		echo "End of File.";
		break;
	}
$data = @file_get_contents("http://domainname.com/index$growloop.html");

preg_match_all('/<p>.*?<a href="([^"]*)".*?<p>.*?href="([^"]*)"/is',$data,$out);
$d = array_combine($out[1], $out[2]);
foreach($d as $k=>$v){
$loopcount++;
echo $loopcount . " - " . $k . "<br>";
$loopcount++;
echo $loopcount . " - " . $v . "<br>";

if ($loopcount == 100){
$growloop = ($growloop + 100);
$loopcount=(0);
echo $growloop . "<br>";
}
}
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.