Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer peopleโ€™s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer peopleโ€™s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:53:41+00:00 2026-05-26T21:53:41+00:00

This has been driving me insane for about the last hour. I’m trying to

  • 0

This has been driving me insane for about the last hour. I’m trying to parse a bit of XML out of Last.fm’s API, I’ve used about 35 different permutations of the code below, all of which have failed. I’m really bad at XML parsing, lol. Can anyone help me parse the first toptags>tag>name ‘name’ from this XML API in PHP? ๐Ÿ™

http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=Owl+city&track=fireflies

Which in that case ^ would be ‘electronic’

Right now, all I have is this

<?
$xmlstr = file_get_contents("http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=Owl+city&track=fireflies");
$genre = new SimpleXMLElement($xmlstr);
echo $genre->lfm->track->toptags->tag->name;
?>

Which returns with, blank. No errors either, which is what’s incredibly annoying!

Thank You very Much ๐Ÿ™‚ ๐Ÿ™‚ ๐Ÿ™‚

Any help greatly, and by greatly I mean really, really greatly appreciated! ๐Ÿ™‚

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:53:41+00:00Added an answer on May 26, 2026 at 9:53 pm

    The <tag> tag is an array, so you should loop through them with a foreach or similar construct. In your case, just grabbing the first would look like this:

    <?
    $xmlstr = file_get_contents("http://ws.audioscrobbler.com/2.0/?method=track.getinfo&api_key=b25b959554ed76058ac220b7b2e0a026&artist=Owl+city&track=fireflies");
    $genre = new SimpleXMLElement($xmlstr);
    echo $genre->track->toptags->tag[0]->name;
    

    Also note that the <lfm> tag is not needed.

    UPDATE

    I find it’s much easier to grab exactly what I’m looking for in a SimpleXMLElement by using print_r(). It’ll show you what’s an array, what’s a simple string, what’s another SimpleXMLElement, etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been driving me crazy for the last couple of hours. I am
This has been driving me mad for the past hour and a half. I
This has been driving me bananas! I'm trying to get my app to publish
Any help is appreciated this has been driving me insane import wx class Frame(wx.Frame):
This has been driving me crazy.. I am trying to return a value from
This has been driving me crazy for 2 days. I have been trying to
This has been driving me insane all day and I think I have the
This has been driving me crazy the past couple of days. I'm trying to
This issue has been driving me up the wall for the last few days.
This issue has been driving me insane. On two separate projects (both of which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.