Return to Snippet

Revision: 23499
at February 8, 2010 19:05 by browncardigan


Initial Code
$cache_file = "/path/to/cache_file.htm";
$force_update = false;

if (filemtime($cache_file)+600 < time() || $force_update) {
	
	ob_start();

	$username = "YOUR_USER_NAME";
	$api_key = "YOUR_API_KEY";

	$url = "http://ws.audioscrobbler.com/2.0/?format=json&method=user.getrecenttracks&";
	$url .= "user=" . $username . "&api_key=" . $api_key;

	$data = @curlContents($url);
	$data = @json_decode($data, true);

	if (isset($data['recenttracks']['track'])) {
		echo '<ul>' . "\n";
		foreach ($data['recenttracks']['track'] as $track) {
			echo '<li>' . $track['artist']['#text'] . ' - ' . $track['name'] . '</li>' . "\n";
		}
		echo '</ul>' . "\n";
	}
	
	$contents = ob_get_contents();
	ob_end_clean();
	
	file_put_contents($cache_file, $contents);
	
}

else {
	$contents = file_get_contents($cache_file);
}

echo $contents;

Initial URL
http://bettesmidler.com

Initial Description


Initial Title
last fm recent tracks

Initial Tags


Initial Language
PHP