这是来自上一个fm的xml响应:
<lfm status="ok">
<artist>
<name>Adele</name>
<mbid>1de93a63-3a9f-443a-ba8a-a43b5fe0121e</mbid>
<url>http://www.last.fm/music/Adele</url>
<image size="small">http://userserve-ak.last.fm/serve/34/71796928.png</image>
<image size="medium">http://userserve-ak.last.fm/serve/64/71796928.png</image>
<image size="large">http://userserve-ak.last.fm/serve/126/71796928.png</image>
<image size="extralarge">http://userserve-ak.last.fm/serve/252/71796928.png</image>
<image size="mega">http://userserve-ak.last.fm/serve/_/71796928/Adele+PNG.png</image>
...
我试图回应那个大图像,但它没有返回任何东西......
<?php
$xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=ARTISTNAME&api_key=b25b959554ed76058ac220b7b2e0a026");
$largeimg = $xml->artist->image['large'];
echo '<img src="'.$largeimg.'" />';
?>
如果我只是把$ largeimg = $ xml-&gt; artist-&gt; image;它只抓住第一张图片(小图片)。知道如何解决这个问题吗?
答案 0 :(得分:1)
使用PHP's children() function获取艺术家节点的孩子:
$artistTag= $xml->artist->children();
$largeImage = $artistTag[5]; // 5 is the index of the Large Image child