0

最近我的代码出现了一些问题,这些问题需要从 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,但我对使用它一无所知,因此将不胜感激那里的一些帮助。

4

2 回答 2

0

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
于 2012-05-09T18:11:12.367 回答
0

你打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;

卷曲版本:

<?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);
于 2017-05-28T10:59:58.067 回答