Jump to content

Pull the top 20 from last.fm


gesseg

Recommended Posts

Hi I need to pull the top 20 from my last.fm account. Last.fm provide an API key (?) Heres the link to mine http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=sandi-g&api_key=b25b959554ed76058ac220b7b2e0a026 I need to search this string (as html code not what a browser outputs) for "<name>" and then return all character untill the next "<" the search on again for the next "<name>" all the way up to 20.

 

Ive not got very far on this one to be honest. I dont even know how to search it as plain txt. I dont necessarily want some one to do it for me but bare in mind Ive only been coding for a few days.

Link to comment
https://forums.phpfreaks.com/topic/204723-pull-the-top-20-from-lastfm/
Share on other sites

sorry, it does return xml. Ive had a play round with parsing the xml. and ive got the script working but I dont understand enought to make it do what i want  :shrug:

 

I want it to only output the </name> tags. Anyway heres the code i have:

<?php 

$file = "http://ws.audioscrobbler.com/2.0/?method=user.gettopartists&user=sandi-g&12month&api_key=b25b959554ed76058ac220b7b2e0a026"; 

function contents($parser, $data){ 
    echo $data; 
} 

function startTag($parser, $data){ 
    echo "<b>"; 
} 

function endTag($parser, $data){ 
    echo "</b><br />"; 
} 

$xml_parser = xml_parser_create(); 

xml_set_element_handler($xml_parser, "startTag", "endTag"); 

xml_set_character_data_handler($xml_parser, "contents"); 

$fp = fopen($file, "r"); 

$data = fread($fp, 3368500); 

if(!(xml_parse($xml_parser, $data, feof($fp)))){ 
    die("Error on line " . xml_get_current_line_number($xml_parser)); 
} 

xml_parser_free($xml_parser); 

fclose($fp); 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.