Jump to content

PHP Foreach Error! Pls Help!


Miteshsach86

Recommended Posts

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  :(  :-\  :confused:

 

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

Link to comment
https://forums.phpfreaks.com/topic/215867-php-foreach-error-pls-help/
Share on other sites

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.