0

我从 Flickr 得到了正确的回复,即:

<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
  <photoset id="72157630469695108" owner="15823425@N00" primary="5110549866" secret="fd716fb5ee" server="1136" farm="2" photos="101" count_views="67" count_comments="0" count_photos="101" count_videos="0" can_comment="0" date_create="1341701808" date_update="1345054078">
    <title>Montana</title>
    <description />
  </photoset>
</rsp>

由于某种原因,我无法获得标题,我尝试了以下方法:

$album_info = simplexml_load_file($album_info_xml); // this is what the response is stored in

echo $album_info['photoset']['title'];

foreach($album_info->photoset as $ps) {
    echo $ps['title'];
}

还有其他一些疯狂的事情,我知道这很愚蠢,但不知道我错过了什么。

可以在这里看到响应:http: //www.flickr.com/services/api/explore/flickr.photosets.getInfo

只需72157630469695108用作集合 id 或使用此 url:http ://api.flickr.com/services/rest/?method=flickr.photosets.getInfo&api_key=7ccedd2c89ca10303394b8085541d9de&photoset_id=72157630469695108

4

2 回答 2

1

您应该SimpleXMLElement直接使用,然后xpath找到您的节点。

$album_info = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
  <photoset id="72157630469695108" owner="15823425@N00" primary="5110549866" secret="fd716fb5ee" server="1136" farm="2" photos="101" count_views="67" count_comments="0" count_photos="101" count_videos="0" can_comment="1" date_create="1341701808" date_update="1345054078">
    <title>Montana</title>
    <description />
  </photoset>
</rsp>'); // this is what the response is stored in

$result = $album_info->xpath('//title');

foreach ($result as $title)
{
  echo $title . "\n";
}

工作示例

于 2012-08-23T12:01:10.213 回答
0

对于处于相同位置的任何人,这都成功了

$albumName = $album_info->photoset->title;
于 2012-08-23T12:32:14.830 回答