Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用simplexml加载文件从XML提要提取数据_Php_Xml_Api_Rss_Simplexml - Fatal编程技术网

Php 使用simplexml加载文件从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-&

我正在尝试使用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->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获取提要要好。