[英]Display Artist Info from Last.FM API
Having recently had some problems with my code which calls for artist data fed from Last.FM API, I'm looking for a different solution but am struggling to find a nice easy way to handle the problem. 最近,我的代码遇到了一些问题,这些问题需要使用Last.FM API提供的艺术家数据,我正在寻找其他解决方案,但仍在努力寻找一种解决问题的简便方法。 Currently I have:
目前我有:
<?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; ?>
Obviously, this is a problem for security as I don't want to enable fopen. 显然,这是安全性的问题,因为我不想启用fopen。 Can anyone point me in the direction of a solution?
谁能指出我的解决方案方向? Most people suggest cURL but I have no clue about using it so would be grateful for some help there.
大多数人建议使用cURL,但我对使用cURL不了解,因此不胜感激。
cURL is a PHP library. cURL是一个PHP库。 Here are some links that explain it well:
这里有一些链接可以很好地解释它:
http://themekraft.com/getting-json-data-with-php-curl/ http://www.jonasjohn.de/snippets/php/curl-example.htm http://themekraft.com/getting-json-data-with-php-curl/ http://www.jonasjohn.de/snippets/php/curl-example.htm
For others who may read this: If your hosting company doesn't have fopen enabled, you may be able to create a "local" php.ini file in your web root directory with this line: 对于其他可能会读到此内容的用户:如果托管公司未启用fopen,则可以使用以下命令行在Web根目录中创建“本地” php.ini文件:
allow_url_fopen = ON
You called simplexml_load_file
twice. 您两次调用了
simplexml_load_file
。 Try: 尝试:
<?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 version: 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.