I am using the zend framework to get info from the audioscrobbler api. The response format is like this:
我正在使用zend框架从audioscrobbler api获取信息。响应格式如下:
<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?
我怎样才能获得现在的价值?
3 个解决方案
#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:
根据Zend Framework API文档,您将获得一个SimpleXML对象。您可以使用它的attributes()方法读取SimpleXMLElement的属性:
$track->attributes()->nowplaying
#2
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.
我没有在任何地方的文档中看到它。
#3
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.
对于这个主题并不是很了解(除了Audioscrobbler协议),谷歌搜索似乎表明$ track-> getAttribute(“nowplaying”)应该可以解决问题。 HTH。
#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:
根据Zend Framework API文档,您将获得一个SimpleXML对象。您可以使用它的attributes()方法读取SimpleXMLElement的属性:
$track->attributes()->nowplaying
#2
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.
我没有在任何地方的文档中看到它。
#3
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.
对于这个主题并不是很了解(除了Audioscrobbler协议),谷歌搜索似乎表明$ track-> getAttribute(“nowplaying”)应该可以解决问题。 HTH。