LinkedIn Facebook Twitter


Get last.fm Top Weekly Artist Chart to your Web site with PHP

December 17th, 2010 | Php

I enjoy to play with json and xml files but did not use simplexml before. Dean Harris has a great script that pulls top tracks from last.fm. I needed one that is gonna pull the weekly chart. Changed his script a bit and here is the result.

Source Code

// Set up the required variables first
$method = "user.getweeklyartistchart"; //Enter method. Visit http://www.last.fm/api for more methods
$username = "username"; // Enter your username here
$apikey = "api key"; // Enter your API Key here. Visit http://www.last.fm/api/account if you dont have one
$limit = 5; //Enter the number of artist will be displayed

// Construct the URL, and feed it through SimpleXML
$feed = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=".$method."&user=".$username."&api_key=".$apikey);

//Get Artists
$artist = $feed->weeklyartistchart->artist;

//Print Chart
	$a = $artist[$i];
	echo "#".($i+1)." - ".$a->name." - ".$a->playcount." plays 
"; }

You can also visit http://www.last.fm/tools/charts?subpage=gallery#gallery, generate your chart style and get the list to your website.

Responses to "Get last.fm Top Weekly Artist Chart to your Web site with PHP"

  1. Patrick says:

    Works for me. Thanks 🙂

Leave a Reply