$lastfmUsername = $userinfo['field8'];
$numberOfSongs = 10; // 10 is max
if (strlen($lastfmUsername) > 2) {
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://ws.audioscrobbler.com/1.0/user/$lastfmUsername/recenttracks.txt");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
$recentlyPlayedSongs = curl_exec($ch);
curl_close($ch);
$ch2 = curl_init();
curl_setopt ($ch2, CURLOPT_URL, "http://ws.audioscrobbler.com/1.0/user/$lastfmUsername/topartists.txt");
curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch2, CURLOPT_CONNECTTIMEOUT, 5);
$topartists = curl_exec($ch2);
curl_close($ch2);
$topartists = utf8_decode($topartists);
$recentlyPlayedSongs = utf8_decode($recentlyPlayedSongs);
//echo $recentlyPlayedSongs;
$track = explode("\n", $recentlyPlayedSongs);
for ($i = 0; $i < $numberOfSongs; $i++) {
$trackArray = explode(",", $track[$i]);
$tracks .= $trackArray[1]."
";
}
$ta = explode("\n", $topartists);
for ($i = 0; $i < $numberOfSongs; $i++) {
$taArray = explode(",", $ta[$i]);
$tafinal .= $taArray[1]." - ";
$tafinal .= $taArray[2]."
";
}
}