Php 使用simplexml加载文件从XML提要提取数据
我正在尝试使用simplexml\u load\u文件从XML提要提取数据。这就是我现在拥有的:Php 使用simplexml加载文件从XML提要提取数据,php,xml,api,rss,simplexml,Php,Xml,Api,Rss,Simplexml,我正在尝试使用simplexml\u load\u文件从XML提要提取数据。这就是我现在拥有的: <?php $anobii = simplexml_load_file('http://www.anobii.com/rss_shelf?s=01fe251a6c442bbf8a'); foreach ($anobii->entry as $anobiiinfo): $title=$anobiiinfo->rss-&
<?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
)。您应该按照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;
?>
您应该按照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;
?>
谢谢!!:D它起作用了!最新问题:您认为使用此方法(文件获取内容)或WordPress内置函数获取提要(基于SimplePie)更好/更快吗?再次感谢!:)我更喜欢使用fetch_提要,这应该比使用rs URL获取提要要好。谢谢!!:D它起作用了!最新问题:您认为使用此方法(文件获取内容)或WordPress内置函数获取提要(基于SimplePie)更好/更快吗?再次感谢!:)我更喜欢使用fetch_提要,这应该比使用rsurl获取提要要好。