如何获得所有的图像与最后的艺术家.fm API(需要示例)PHP


How to get all images for an artist with Last.fm API (Need examples) PHP

$return =" http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&api_key="。自我:API_KEY。",艺术家= "。美元的艺术家。= " ",专辑。美元的专辑。= " ",形象。self:: $ size_map[美元]大小。"和格式= json";

$ htmlContent = file_get_contents (" http://www.last.fm/fr/music/"艺术家。美元/+图片),

// We'll add all the images in this array
$images = array();
// Instantiate a new object of class DOMDocument
$doc = new DOMDocument();
// Load the HTML doc into the object
libxml_use_internal_errors(true);
$doc->loadHTML($htmlContent);
libxml_use_internal_errors(false);
// Get all the IMG tags in the document
$elements = $doc->getElementsByTagName('img');
// If we get at least one result
if($elements->length > 0)
{
   // Loop on all of the IMG tags
   foreach($elements as $element)
   {
      // Get the attribute SRC of the IMG tag (this is the link of the image)
      $src = $element->getAttribute('src');
      if (strlen($src) > 0) {
        // Add the link to the array containing all the links
        array_push($images, $src);
      }
   }