Skip to content

Instantly share code, notes, and snippets.

What would you like to do? Simple PHP Class
$lastfm = new LastFm('your-api-key');
$params = array(
'user' => 'mloberg'
print_r($lastfm->call('user.getInfo', $params));
$tracks = $lastfm->call('user.getRecentTracks', $params);
foreach($tracks['recenttracks']['track'] as $track){
echo $track['name'].' by '.$track['artist']['#text'].'<br />';
* This simple php class was written by Matthew Loberg (
class LastFm{
private $api_key;
const url = '';
function __construct($api_key){
$this->api_key = $api_key;
function call($method,$params=array()){
$lastfm = self::url.'?method='.$method.'&format=json&api_key='.$this->api_key;
foreach($params as $key => $value){
$lastfm .= '&'.$key.'='.urlencode($value);
$json = file_get_contents($lastfm);
return json_decode($json, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.