It's been a while since i've done any coding in php, been learning java recently and I guess it's all getting messed up in my head. I had the idea of parsing .xml files from last.fm and making various graphs of my listening habits etc. but ran into a couple of problems:
#1: I have an array of dates in unix time but when I try to echo them using the date function I get this error:
#2: The following code should print out the playcount of an artist if it is in my $top10Artists array. For some reason $t never equals $a->name.
#1: I have an array of dates in unix time but when I try to echo them using the date function I get this error:
| Code: |
| Warning: date() expects parameter 2 to be long, object given in D:\brick\www\xmlparsing.php on line 42 |
#2: The following code should print out the playcount of an artist if it is in my $top10Artists array. For some reason $t never equals $a->name.
| Code: |
| $user = "woodenbrick";
$url = "http://ws.audioscrobbler.com/1.0/user/$user"; $topArtistsOverall = "$url/topartists.xml"; $weeklyArtists = "$url/weeklyartistchart.xml"; $chartlists = "$url/weeklychartlist.xml"; //get top 10 current artists $top10Artists = array(); $xml = simplexml_load_file($topArtistsOverall) or die ("Couldnt load $topArtistsOverall"); for($x = 0; $x < 10; $x++){ $top10Artists[] = $xml->artist[$x]->name; } //get list of chart dates $xml = simplexml_load_file($chartlists) or die("Couldnt load $chartlists"); $from = array(); $to = array(); foreach($xml->chart as $chart){ $from[] = $chart['from']; $to[] = $chart['to']; } //this part of the script will take some time to execute, since only //allowed to access audioscrobbler once per second apparently(52 seconds for a year of charts) for($x=0; $x<sizeof($from); $x++){ echo "<p />Charts from ".date("d m y", $from[$x])." to ".date("d m y", $to[$x])."<br />";//error #1 here $currentXml = "$weeklyArtists?from=".$from[$x]."&to=".$to[$x]; $xml = simplexml_load_file($currentXml) or die("couldnt load $currentXml"); foreach($xml->artist as $a){ foreach($top10Artists as $t){ if($t == $a->name){ echo "$a->name Playcount: $a->playcount<br />";//error #2 here } } //} } sleep(1); } |
