繁体   English   中英

从Last.FM API显示艺术家信息

[英]Display Artist Info from Last.FM API

最近,我的代码遇到了一些问题,这些问题需要使用Last.FM API提供的艺术家数据,我正在寻找其他解决方案,但仍在努力寻找一种解决问题的简便方法。 目前我有:

    <?php $feed = simplexml_load_file("http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=anartistname&api_key=01234567890");
$xml = simplexml_load_file($feed);
$info = $xml->artist->bio->summary; ?>

<?php echo $info; ?> 

显然,这是安全性的问题,因为我不想启用fopen。 谁能指出我的解决方案方向? 大多数人建议使用cURL,但我对使用cURL不了解,因此不胜感激。

cURL是一个PHP库。 这里有一些链接可以很好地解释它:

http://themekraft.com/getting-json-data-with-php-curl/ http://www.jonasjohn.de/snippets/php/curl-example.htm

对于其他可能会读到此内容的用户:如果托管公司未启用fopen,则可以使用以下命令行在Web根目录中创建“本地” php.ini文件:

allow_url_fopen = ON

您两次调用了simplexml_load_file 尝试:

<?php

$feed = 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=anartistname&api_key=YOUR_KEY';
$xml = simplexml_load_file($feed);
$info = $xml->artist->bio->summary;

echo $info;

cURL版本:

<?php

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=anartistname&api_key=YOUR_KEY');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$xml = curl_exec($ch);
curl_close($ch);

$xml = simplexml_load_string($xml);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM