User325313 User325313 - 3 months ago 17
PHP Question

Extract full list of rss feed using simplexml_load_file

I'm using a code to extract the items from an ebay rss feed, the only problem is that it is only extracting one item.

I suspected it was because of

for each
, but after searching this whole site, I couldn't find a solution. The feed URL will output 8 items (entriesPerPage=8), if you access the feed, you'll that the full xml code is there, but the parser is only getting one item.

<?php

$feedurl = "http://rest.ebay.com/epn/v1/find/item.rss?keyword=%28jewelry%2Ccraft%2Cclothing%2Cshoes%2Cdiy%29&sortOrder=BestMatch&programid=1&campaignid=5337945426&toolid=10039&listingType1=All&lgeo=1&topRatedSeller=true&hideDuplicateItems=true&entriesPerPage=8&feedType=rss";

$rss = simplexml_load_file($feedurl);

foreach ($rss->channel->item as $item) {

$link = $item->link;

$title = $item->title;

$description = $item->description;

}

?>
<div class="mainproductebayfloatright-bottom">
<div class="aroundebay">
<?
print "<div class=\"titleebay\">" . $title . "</div>";
print $description;
?>
</div>
</div>

?>

Answer

Move your html inside a loop, as currently on each iteration your variables are overwritten and after the loop is over what you have is values of the last xml-item:

foreach ($rss->channel->item as $item) {
    $link = $item->link;
    $title = $item->title;
    $description = $item->description;?>
    <div class="mainproductebayfloatright-bottom">
        <div class="aroundebay">
    <?php
        print "<div class=\"titleebay\">" . $title . "</div>";
        print $description;
    ?>
        </div>
    </div>
<?php
}
Comments