Miteshsach86 Posted October 14, 2010 Share Posted October 14, 2010 Hi Guys, I really hope one of you clever genious's can help me. Below is a code which I derived myself, it basically opens up the amazon website on to the page, scrapes everything in between the body tags and then it's supposed to filter out everything into <p></p> tags. But I'm getting the following error :-\ Warning: Invalid argument supplied for foreach() in /var/www/vhosts/...scrapeamazon.php on line 13 <?php $bbc = "http://www.amazon.co.uk/"; preg_match_all('/<body[^>]*>\s*(.*?)\s*<\/body>/is',file_get_contents($bbc), $bbcwebsite); $bodytags = $bbcwebsite[1]; if(empty($bodytags) || $bodytags == NULL) { $bbcbody = "Nothing here 1!"; } else { foreach ($bodytags as $line_num => $link) { $bbcbody = $link . "<br />\n"; preg_match_all('/<p[^>]*>\s*(.*?)\s*<\/p>/is', $bbcbody, $bbcp); $pcontent = $bbcp[1] . "<br />\n"; if(empty($pcontent) || $pcontent == NULL) { $bbcptag = "Nothing here 2!"; } else { foreach ($pcontent as $line_num => $ptag) { $bbcptag .= $ptag . "<br />\n"; } } } } ?> I would really appreciate someone's help and thank you in advance. M Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 14, 2010 Share Posted October 14, 2010 apparently $bodytags is not an array. try print_r($bodytags) to check. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 14, 2010 Share Posted October 14, 2010 You're concatenating a string "<br />\n" with an array $bbcp[1] which gives you a string $pcontent, which you can't operate on with foreach(). Quote Link to comment Share on other sites More sharing options...
Miteshsach86 Posted October 14, 2010 Author Share Posted October 14, 2010 Thanks BlueSkyIS but that the error I was getting. However AbraCadaver my friend, you are a genious! Thank you! 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.