PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Dan Moffat Mood   test.php   Download  
File: test.php
Role: Example script
Content type: text/plain
Description: Show example usage of all methods
Class: Mood
Search for artist or tracks in
Author: By
Last change: Added example usage of how you would get the 2nd, 3rd, 4th and so on tracks from the getArtistTrack() method.
Date: 12 years ago
Size: 1,831 bytes


Class file image Download

//Path to class

//Define tag and API key here
$tag = 'pop punk';
$key = '';

//Instantiate Lastfm_Mood object, it requires 2 params, tag e.g. Indie, Sad etc. and a API key.
$lfm = new Lastfm_Mood($tag,$key);

//Prints the tag set
echo "<p>Tag name: ".$lfm->getTag()."</p>";

//Prints the top artist for specified tag
echo "<p>Artist name: ".$lfm->getArtist()."</p>";

//Prints the top track for the artist generated from getArtist()
echo "<p>Artists top track: ".$lfm->getArtistTrack('single')."</p>";

//Returns an array of top tracks from the artist generated from getArtist()
echo "<p>Artists top tracks: ".$lfm->getArtistTrack('list')."</p>";

//Returns the n'th track from the top tracks
$track = array();
$trackno = 3;
$lfm->getArtistTrack('list') as $t){
$track[] = $t;
//Will return the 3rd result of the search
echo $track[$trackno];

//Prints a formatted URL based on artist and trackname supplied, no validation of if they exist, use with care
echo "<p> formatted link: ".$lfm->getLink('Millencolin', 'No Cigar')."</p>";

//Example of the above using the artist and artist track generated
echo "<p> formatted link with dynamic content: ".$lfm->getLink($lfm->getArtist(), $lfm->getArtistTrack())."</p>";

//Generates a button, first param is link, second is text displayed
echo "<p> 'button': ".$lfm->getButton('','Test Text')."</p>";

//Example of above using generated link from the generated artist/trackname, uncomment line.
//WARNING: Slow! Sometimes causes timeout, use with caution.
//echo "<p> dynamic 'button': ".$lfm->getButton($lfm->getLink($lfm->getArtist(), $lfm->getArtistTrack('single')), 'Dynamically generated goodness!')."</p>";