PHP Warning: Invalid argument supplied for foreach()
<p>Why am I getting a PHP Warning:  Invalid argument supplied for foreach()</p>

<p>These three sections in my Script.</p>

<h1>1</h1>

<pre><code>// look for text file for this keyword
if (empty($site["textdirectory"])) {
    $site["textdirectory"] = "text";
}
if (file_exists(ROOT_DIR.$site["textdirectory"].'/'.urlencode($q).'.txt')) {
    $keywordtext = file_get_contents(ROOT_DIR.$site["textdirectory"].'/'.urlencode($q).'.txt');
}
else {
    $keywordtext = null;
}

$keywordsXML = getEbayKeywords($q);

foreach($keywordsXML-&gt;PopularSearchResult as $item) {
    $topicsString = $item-&gt;AlternativeSearches;
   $relatedString = $item-&gt;RelatedSearches;
   if (!empty($topicsString)) {
        $topics =  split(";",$topicsString);
    }
    if (!empty($relatedString)) {
        $related = split(";",$relatedString);
    }

}

$node = array();
$node['keywords'] = $q;
</code></pre>

<h1>2</h1>

<pre><code>$xml = ebay_rss($node);

$ebayItems = array();
$totalItems = count($xml-&gt;channel-&gt;item);

$totalPages = $totalItems / $pageSize;


$i = 0;
foreach  ($xml-&gt;channel-&gt;item as $item) {
  $ebayRss = $item-&gt;children('http://www.ebay.com/marketplace/search/v1/services');

    if ($i&gt;=($pageSize*($page-1)) &amp;&amp; $i&lt;($pageSize*$page)) {
        $newItem = array();
        $newItem['title'] = $item-&gt;title;
        $newItem['link'] = buyLink($item-&gt;link, $q);
        $newItem['image'] = ebay_stripImage($item-&gt;description);
        $newItem['currentbid'] = ebay_convertPrice($item-&gt;description);
        $newItem['bidcount'] = $ebayRss-&gt;BidCount;
        $newItem['endtime'] = ebay_convertTime($ebayRss-&gt;ListingEndTime);
        $newItem['type'] = $ebayRss-&gt;ListingType;
        if (!empty($ebayRss-&gt;BuyItNowPrice)) {
            $newItem['bin'] = ebay_convertPrice($item-&gt;description);
        }
        array_push($ebayItems, $newItem);
    }
    $i++;
}


$pageNumbers = array();
for ($i=1; $i&lt;=$totalPages; $i++) {
    array_push($pageNumbers, $i);
}
</code></pre>

<h1>3</h1>

<pre><code>// get user guides
$guidesXML = getEbayGuides($q);
$guides = array();
foreach ($guidesXML-&gt;guide as $guideXML) {
    $guide = array();
    $guide['url'] = makeguideLink($guideXML-&gt;url, $q);
    $guide['title'] = $guideXML-&gt;title;
    $guide['desc'] = $guideXML-&gt;desc;
    array_push($guides,$guide);
}
</code></pre>
