我正在使用代码从ebay rss提取中提取项目,唯一的问题是它只提取一个项目。
我怀疑这是因为for each
,但在搜索整个网站后,我找不到解决方案。提要URL将输出8个项目(entriesPerPage = 8),如果您访问该提要,您将看到完整的xml代码,但解析器只获得一个项目。
<?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>
?>
答案 0 :(得分:0)
将html移动到一个循环中,因为当前每次迭代时你的变量都被覆盖,并且在循环结束后你所拥有的是最后一个xml项的值:
foreach ($rss->channel->item as $item) {
$link = $item->link;
$title = $item->title;
$description = $item->description;?>
<div class="mainproductebayfloatright-bottom">
<div class="aroundebay">
<?php
// simple title
print "<div class=\"titleebay\">" . $title . "</div>";
// title-link
print "<a href=\"" . $link . "\">" . $title . "</div>";
print $description;
?>
</div>
</div>
<?php
}