2012-04-05 67 views
0

这是从去年FM XML响应:获得来自last.fm XML(API artist.getinfo)大艺术家图像

<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-> artist-> image;它只是抓住第一张图片(小图片)。任何想法如何我可以解决这个问题?

回答

1

使用PHP's children() function得到艺术家节点的孩子:

$artistTag= $xml->artist->children(); 
$largeImage = $artistTag[5]; // 5 is the index of the Large Image child 
相关问题