很好,我有这个代码的LastFM API
<?php
$xml = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=ARIANA GRANDE&api_key=b25b959554ed76058ac220b7b2e0a026");
$largeImage = $xml->xpath('/lfm/artist/image[@size="mega"]')[0];
echo '<img src="'.$largeImage.'" />';
?>
它似乎使用了Ariana Grande的图像一个php页面。
现在我的XML文件的链接是:http://radiojoven.6te.net/playlist.xml
好吧,我想做的是用我的XML文件提供的信息更改"simplexml_load_file"(php代码中)链接中的"ARIANA GRANDE"(艺术家的名字)。我试图制作这样的代码,但没有成功。
<?php
$xml = simplexml_load_file('http://radiojoven.6te.net/playlist.xml');
$artist = urlencode($xml->Event->Song->Artist['name'];);
$url = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist='.$artist.'&api_key=50ac27433c63f7298064f434f4ef6d15);
$xml2 = @simplexml_load_file($url);
$largeImage = $xml2->xpath('/lfm/artist/image[@size="mega"]')[0];
echo '<img src="'.$largeImage.'" />';
?>
你能帮我做这个吗?
提前谢谢大家。
我认为您的代码中有一些错误。
删除此行中['name'];
之后的分号:
$artist = urlencode($xml->Event->Song->Artist['name'];);
api_key=50ac27433c63f7298064f434f4ef6d15
之后缺少双引号,我认为'.$artist.'
应该是此行中的$artist
:
$url = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist='.$artist.'&api_key=50ac27433c63f7298064f434f4ef6d15);
我认为你不需要这条线:
$xml2 = @simplexml_load_file($url);
然后在此行中,将$xml2
更改为$url
:
$largeImage = $xml2->xpath('/lfm/artist/image[@size="mega"]')[0];
所以你的代码会变成这样:
<?php
$xml = simplexml_load_file('http://radiojoven.6te.net/playlist.xml');
$artist = urlencode($xml->Event->Song->Artist['name']);
$url = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=$artist&api_key=50ac27433c63f7298064f434f4ef6d15");
$largeImage = $url->xpath('/lfm/artist/image[@size="mega"]')[0];
echo '<img src="'.$largeImage.'" />';
?>