mixed lastfm_recent(string user) -- Retrieve a user's recent tracks from last.fm
<?php |
This will output:
matchbox twenty - Disease |
Published under the terms of the BSD License
<?php
function lastfm_recent($user) {
$url = sprintf('http://ws.audioscrobbler.com/1.0/user/%s/recenttracks.xml', urlencode($user));
$xml = new XMLReader();
if (@$xml->open($url)) {
$ret = array();
while ($xml->read()) {
switch($xml->nodeType) {
case XMLReader::ELEMENT:
/* Start elements */
$element = $xml->name;
switch($xml->name) {
case 'track':
$track = array();
break;
case 'date':
$track['date_uts'] = $xml->getAttribute('uts');
break;
case 'artist':
$track['artist_mbid'] = $xml->getAttribute('mbid');
break;
}
break;
case XMLReader::END_ELEMENT:
/* End elements */
switch($xml->name) {
case 'track':
$ret[] = $track;
break;
}
break;
case XMLReader::TEXT:
/* Text nodes */
$track[$element] = $xml->value;
break;
}
}
$xml->close();
}
else {
$ret = false;
}
return $ret;
}
?>
Last updated: Sat Jun 14 20:02:45 CEST 2008