This code displays the Top 50 artists XML feed from last.fm in a nice presentable way on your website. Can easily be modified to work with any other feed from last.fm, find the full guide at http://www.strydominc.za.net/index.php?p=projectdetail&d=phplastfmchart
1
2 <?php
3 /**********************************************************************************************
4 www.strydominc.za.net
5 Created by Jurgen Strydom, 19-08-2006, jurgen.strydom@gmail.com
6 Read the readme.txt
7 Version 1.01, 05-09-2006
8 **********************************************************************************************/
9 ?>
10 <link href="lastfmbar.css" rel="stylesheet" type="text/css">
11 <div>
12 <?php
13 //User settings -> needs your attention
14 $user = "Alkine"; //Your username
15 $width = 700; //width of the list
16
17 //Code you should not worry about
18 $file = "http://ws.audioscrobbler.com/1.0/user/$user/topartists.xml";
19 $xml = simplexml_load_file("$file");
20 $big = $xml->artist[0]->playcount;
21 $total = count($xml->artist);
22 $factor = $width /$big;
23 ?>
24 <table width="<?php echo $width ?>" border="0" cellpadding="0" cellspacing="0">
25 <?php
26 for ($k=0 ; $k<=$total - 1; $k++) {
27 $barlen = round(($xml->artist[$k]->playcount * $factor), 0);
28 ?>
29 <tr>
30 <td width="<?php echo $width ?>" height="10" valign="center"><table width="100%" border="0" cellpadding="0" cellspacing="0">
31 <!--DWLayoutTable-->
32 <tr>
33 <td width="<?php echo $barlen ?>" height="10" valign="center" class="lastfmbar"><?php
34 if ($barlen >= (($width + 100) /2)) {
35 echo "<div align=\"right\">", $xml->artist[$k]->playcount, " - <b>", $xml->artist[$k]->name ,"</b></div>";
36 }
37 if (($barlen < (($width + 100) /2)) && ($barlen >= ($width / 3))) {
38 echo "<div align=\"right\">", $xml->artist[$k]->playcount ," -</div>";
39 }
40 if ($barlen < ($width / 3)) {
41 echo " ";
42 }
43 ?></td>
44 <td width="<?php echo $width - $barlen ?>" valign="center"><?php
45 if ($barlen >= (($width + 100) /2)) {
46 echo " ";
47 }
48 if (($barlen < (($width + 100) /2)) && ($barlen >= ($width / 3))) {
49 echo "<div align=\"left\"><b> ", $xml->artist[$k]->name ,"</b></div>";
50 }
51 if ($barlen < ($width / 3)) {
52 echo "<div align=\"left\">", $xml->artist[$k]->playcount, " - <b>", $xml->artist[$k]->name ,"</b></div>";
53 }
54 ?></td>
55 </tr>
56 </table></td>
57 </tr>
58 <?php
59 }
60 ?>
61 </table>
62 </div>
63 <?php
64 /**********************************************************************************************
65 Changelog:
66
67 Version 1.01
68 Fixed a bug that caused the bar sizes to display incorrectly.
69
70 Version 1
71 First release.
72 **********************************************************************************************/
73 ?>