簡體   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