last.fm weeklyartistchart
Не забудте поменять uname, even и odd должны быть описаны в css…
<?php
$uname = ‘pestbarn’;
#username input
$file = fopen(“http://ws.audioscrobbler.com/1.0/user/$uname/weeklyartistchart.xml”, “r”);
#fopen the rss file
if (!$file) {
echo “Cannot open XML file.”;
} else {
$title = ‘<table style=”width: 100%;”>
’;
$i = 0;
while (!feof ($file)) {
if (!($i++ % 2)) { #optional every other row coloring
$data = ‘even’;
} else {
$data = ‘odd’;
} #you can style this with css classes ”even” and ”odd”
$line = fgets ($file, 1024);
if (eregi (“<name>(.*)</name>”, $line, $out)) { #output links and track info
$output = $out[1];
$output = explode(“ - ”, $output, 2);
$output = str_replace(“ ”, “+”, $output); #switch to plus sign for urls
$artist = str_replace (“+”, “ ”, $output[0]); #switch to spaces for artist names
$title .= ‘
<tr class=”‘. $data .‘”>
<td>
<a href=”http://www.last.fm/music/’. $output[0] .‘”>’. $artist .‘</a>
</td>’;
}
if(eregi (“<playcount>(.*)</playcount>”, $line, $out)) {
$title .= ‘<td style=”text-align: right;”>’. $out[1] .‘ plays</td>’;
}
}
$title .= “</table>”;
$title = $title;
echo $title;
fclose($file);
}
?>

