Get large artist image from last.fm xml (api artist.getinfo)

本秂侑毒 提交于 2019-12-23 05:26:49

问题


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.'" />';     
?>

If I just put $largeimg = $xml->artist->image; it just grabs that first image (small one). Any idea how I can fix this?


回答1:


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


来源:https://stackoverflow.com/questions/10027668/get-large-artist-image-from-last-fm-xml-api-artist-getinfo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!