0

I am using the zend framework to get info from the audioscrobbler api. The response format is like this:

  <recenttracks user="RJ">
  <track nowplaying="true">
    <artist mbid="2f9ecbed-27be-40e6-abca-6de49d50299e">Aretha Franklin</artist>
    <name>Sisters Are Doing It For Themselves</name>
    <mbid/>
    <album mbid=""/>
    <url>www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves</url>
    <date uts="1213031819">9 Jun 2008, 17:16</date>
    <streamable>1</streamable>
  </track>
  ...
</recenttracks>

I am accessing elements as such:

$track->name

How can I get the nowplaying value?

Fortyrunner
  • 12,702
  • 4
  • 31
  • 54
Sheehan Alam
  • 60,111
  • 124
  • 355
  • 556

3 Answers3

1

You can give these a try:

$track['nowplaying']

or:

$track->getAttrib('nowplaying')

or:

$attributes = $track->attributes();
echo $attributes['nowplaying']

I don't see it in the docs anywhere though.

pix0r
  • 31,139
  • 18
  • 86
  • 102
1

According to the Zend Framework API Documentation you are getting a SimpleXML object. You can read an attribute of a SimpleXMLElement with it's attributes() method:

$track->attributes()->nowplaying
Patrick Glandien
  • 7,791
  • 5
  • 41
  • 47
0

Not really knowing much about this subject (except for the Audioscrobbler protocol), googling for it seems to indicate that $track->getAttribute("nowplaying") should do the trick. HTH.

Deniz Dogan
  • 25,711
  • 35
  • 110
  • 162