Michdd Posted July 30, 2009 Share Posted July 30, 2009 I guess this question is somewhat about spidering.. I'm writing something that will grab certain things from a web page, it then uses that info to request another web page and get information from that. Repeating this process. I have a function with grabs the necessary stuff so I just do something like this: foreach($something as $part) { $sub = getInfo($part); ... foreach($sub as $subsub) { ... } ... } And I could keep repeating those loops inside each other to go down more and more. But is there a way to do that without actually writing the loops? Say I wanted to go down 10 levels, I don't want to write 10 loops. Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 30, 2009 Share Posted July 30, 2009 You would use recursive methods, so the spider would be a function, and if it finds a link it returns itself (the function) passing that link as a parameter. EDIT: Sample: function sum_series ($sum, $i) { $sum = $sum + $i; if ($i>=10000) { return $sum; }else{ return sum_series($sum, ($i+1); } Quote Link to comment Share on other sites More sharing options...
Michdd Posted July 30, 2009 Author Share Posted July 30, 2009 Oic. That's much better logic than what I'm currently using. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.