phoenixx Posted September 24, 2008 Share Posted September 24, 2008 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>"; } } } ?> Link to comment https://forums.phpfreaks.com/topic/125690-last-try-desperate-please-help-with-foreach-loop-error-handling/ Share on other sites More sharing options...
rarebit Posted September 24, 2008 Share Posted September 24, 2008 I'm quite tired so i've not tried, but the easy solution is to whahap it into a function and use return. Link to comment https://forums.phpfreaks.com/topic/125690-last-try-desperate-please-help-with-foreach-loop-error-handling/#findComment-649947 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.