从last.fm xml(api artist.getinfo)获取大艺术家图像 [英] Get large artist image from last.fm xml (api artist.getinfo)
本文介绍了从last.fm xml(api artist.getinfo)获取大艺术家图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是上一个fm的xml响应:
This is the xml response from last fm:
<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>
...
我试图回显那个大图像,但是它什么也不会返回...
I'm trying to echo that large image, but it doesn't return anything...
<?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;它只是获取第一个图像(小图像).知道我该如何解决吗?
If I just put $largeimg = $xml->artist->image; it just grabs that first image (small one). Any idea how I can fix this?
推荐答案
使用 PHP的孩子( )函数以获取艺术家节点的子代:
Use PHP's children() function to get the artist node's children:
$artistTag= $xml->artist->children();
$largeImage = $artistTag[5]; // 5 is the index of the Large Image child
这篇关于从last.fm xml(api artist.getinfo)获取大艺术家图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文