我正在尝试使用simplexml_load_file从XML Feed中提取数据。这就是我现在所拥有的:
<?php
$anobii = simplexml_load_file('http://www.anobii.com/rss_shelf?s=01fe251a6c442bbf8a');
foreach ($anobii->entry as $anobiiinfo):
$title=$anobiiinfo->rss->channel->item->title;
$desc=$anobiiinfo->rss->channel->item->description;
echo "<span> ",$title,"</span><br><span> ",$desc,"</span>";
endforeach;
?>
问题是我不知道正确的分隔符告诉脚本需要提取的部分(rss->channel->item->title
)。
答案 0 :(得分:4)
Yous应该遵循xml树结构来获取各个项目。
<?php
$feedUrl = 'http://www.anobii.com/rss_shelf?s=01fe251a6c442bbf8a';
$rawFeed = file_get_contents($feedUrl);
$anobii = new SimpleXmlElement($rawFeed);
foreach ($anobii->channel->item as $anobiiinfo):
$title=$anobiiinfo->title;
$desc=$anobiiinfo->description;
echo "<span> ",$title,"</span> <br/> <span> ",$desc,"</span>";
endforeach;
?>