【发布时间】:2015-05-23 01:07:34
【问题描述】:
我使用以下代码从 discogs 的特定记录中获取数据:
//initialize the session
$ch = curl_init();
//Set the User-Agent Identifier
curl_setopt($ch, CURLOPT_USERAGENT, 'MYAPPNAME/0.1 +http://ymysite.com');
//Set the URL of the page or file to download.
curl_setopt($ch, CURLOPT_URL, $url);
//Ask cURL to return the contents in a variable instead of simply echoing them
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//Execute the curl session
$output = curl_exec($ch);
//close the session
curl_close ($ch);
我可以回显 $output,这会给我一个非常复杂的输出:
{"styles": ["Blues Rock", "Rock & Roll"], "videos": [{"duration": 200, "embed": true, "title": "The Rolling Stones - Street Fighting Man", "description": "The Rolling Stones - Street Fighting Man", "uri": "http://www.youtube.com/watch?v=qUO8ScYVeDo"}, {"duration": 2457, "embed": true, "title": "The Rolling Stones - Beggars Banquet FULL ALBUM (mono 黑胶混音)", "description": "The Rolling Stones - Beggars Banquet FULL ALBUM (mono 黑胶混音)", "uri": "http://www.youtube.com/watch?v=sRu88xttBrA"}], "series": [], “标签”:[{“resource_url”:“http://api.discogs.com/labels/5320”,“entity_type”:“1”,“catno”:“SKL 4955”,“id”:5320,“名称”:“Decca”}].. .还有更多...
例如,我如何使用 PHP 从“styles”中获取信息,以便输出“Blues Rock, Rock & Roll”?也许我还想从“描述”中获取信息以输出“滚石乐队 - 乞丐宴会 FULL ALBUM(单黑胶混音)”。
亲切的问候 约翰
【问题讨论】:
标签: php curl discogs-api