gesseg Posted June 14, 2010 Share Posted June 14, 2010 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. Quote Link to comment Share on other sites More sharing options...
l4nc3r Posted June 14, 2010 Share Posted June 14, 2010 Without looking too much in to it (a simple Google query for "last.fm API tutorial" would probably solve all of your problems), I assume the API returns XML. You might want to look up the SimpleXML library in PHP. Quote Link to comment Share on other sites More sharing options...
gesseg Posted June 14, 2010 Author Share Posted June 14, 2010 I doesnt return xml. it would be easier if it did. Quote Link to comment Share on other sites More sharing options...
gesseg Posted June 14, 2010 Author Share Posted June 14, 2010 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 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); ?> Quote Link to comment Share on other sites More sharing options...
salathe Posted June 14, 2010 Share Posted June 14, 2010 What version of PHP are you using? Quote Link to comment Share on other sites More sharing options...
l4nc3r Posted June 14, 2010 Share Posted June 14, 2010 Let's not be lazy, gesseg. There are plenty of places on the internet that explain how XML parsing in PHP works. Visit any one of them and read up and then build your own last.fm parser. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.