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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.