通过LastFM和功能打开歌手图像(artist.getinfo)

Open image of the singer by LastFM and function (artist.getinfo)

很好,我有 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.'" />';     
?>

php 页面似乎使用了 Ariana Grande 的图像。

现在我的 XML 文件的 link 是:http://radiojoven.6te.net/playlist.xml

嗯,我想做的是在 "simplexml_load_file"(在 php 代码中)的 link 中更改 "ARIANA GRANDE"(艺术家的名字)我的 XML 文件提供的信息。我试图制作这样的代码但无济于事。

<?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.'" />';     
?>