使用 simplexml_load_file 提取 rss 提要的完整列表
Extract full list of rss feed using simplexml_load_file
我正在使用代码从 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>
?>
将你的 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
}
我正在使用代码从 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>
?>
将你的 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
}