【发布时间】:2012-12-15 17:21:35
【问题描述】:
我有一个来自 Echonest API 的带有 Spotify URI 的歌曲列表,但它添加了我需要的更多歌曲。我只需要其中一个而不是全部,但我想继续这样做 20 次。所以我只想获取节点内的第一个轨道并继续下一个。
Here is the xml file I get the info from
这是我使用的 PHP:
<iframe src="https://embed.spotify.com/?uri=spotify:trackset:Playlist based on Rihanna:<?php
$completeurl = "http://developer.echonest.com/api/v4/playlist/static?api_key=FILDTEOIK2HBORODV&artist=Rihanna&format=xml&results=20&type=artist-radio&bucket=tracks&bucket=id:spotify-WW";
$xml = simplexml_load_file($completeurl);
$i = 1;
foreach ($xml->xpath('//songs') as $playlist) {
$spotify_playlist = $playlist->foreign_id;
$spotify_playlist2 = str_replace("spotify-WW:track:",'',$spotify_playlist);
echo "$spotify_playlist2,";
if ($i++ == 10) break;
}
?>" width="300" height="380" frameborder="0" allowtransparency="true" style="float: right"></iframe>
【问题讨论】:
-
如果不查看 XML 或查看输出,您将不清楚您的确切含义。请更新您的问题。
-
需要澄清两个具体点:a)“我只想获取节点内的第一个轨道并移动到下一个”节点内的第一个轨道(
<song>?)和下一个什么(播放列表?)? b) 您的代码在<songs>元素上循环,但您的示例仅包含一个,并且它下面没有<foreign_id>节点;这段代码真的有效吗?