views:

159

answers:

3

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?

+1  A: 

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
thx for the tips, i tried those out with no luck unfortunately.
Sheehan Alam
A: 

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
+1  A: 

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 Daryll Glandien