用下面的代碼我沒有你想要什麼:
<?php
$url = 'https://api.deezer.com/2.0/search?q=sam%20smith';
$jsonStr = file_get_contents($url);
$jsonArr = json_decode($jsonStr, true);
$coverXlCollection = array();
foreach ($jsonArr['data'] as $row) {
$coverXlCollection[] = $row['album']['cover_xl'];
}
echo '<pre>'.print_r($coverXlCollection, true).'</pre>';
?>
而結果是:
Array
(
[0] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[1] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[2] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[3] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[4] => https://cdns-images.dzcdn.net/images/cover/5ef4779d20ab952d346e185f3b1dbce7/1000x1000-000000-80-0-0.jpg
[5] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[6] => https://cdns-images.dzcdn.net/images/cover/75e56110a5cef30a4518a075d10ad05e/1000x1000-000000-80-0-0.jpg
[7] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[8] => https://cdns-images.dzcdn.net/images/cover/e44468007c45f2523d056a0b19eed80a/1000x1000-000000-80-0-0.jpg
[9] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[10] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[11] => https://cdns-images.dzcdn.net/images/cover/b962a96a59b95fd1c571e911a9548736/1000x1000-000000-80-0-0.jpg
[12] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[13] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[14] => https://cdns-images.dzcdn.net/images/cover/305b58c95901abbe0caa4060ce010402/1000x1000-000000-80-0-0.jpg
[15] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[16] => https://cdns-images.dzcdn.net/images/cover/2a9aa91b1a681f1b34a313ef9fb73740/1000x1000-000000-80-0-0.jpg
[17] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[18] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[19] => https://cdns-images.dzcdn.net/images/cover/231c66c0ed260c708163eff3bb8458da/1000x1000-000000-80-0-0.jpg
[20] => https://cdns-images.dzcdn.net/images/cover/7029607d87e45f2f48b8e5686a94d20a/1000x1000-000000-80-0-0.jpg
[21] => https://cdns-images.dzcdn.net/images/cover/80b66c217a1711b7aa9ad7fb37bee8b8/1000x1000-000000-80-0-0.jpg
[22] => https://cdns-images.dzcdn.net/images/cover/a073bd9a28dd2ef46c4014ff3968545a/1000x1000-000000-80-0-0.jpg
[23] => https://cdns-images.dzcdn.net/images/cover/a073bd9a28dd2ef46c4014ff3968545a/1000x1000-000000-80-0-0.jpg
[24] => https://cdns-images.dzcdn.net/images/cover/a073bd9a28dd2ef46c4014ff3968545a/1000x1000-000000-80-0-0.jpg
)
我做了一些修改您的代碼和我用json_decode()
函數與第二個參數ameter true
。在這種情況下,你的結果是數組而不是對象。
乾杯。
你想要檢索什麼?藝術家的照片或您找到的第一張專輯封面? – karliwson
@karliwson我想從函數中刪除的內容更合適(cover_xl)https:\/\/cdns-images.dzcdn.net \/images \/cover \/1c7a7c081a1e7787321f81a889e9f7b8 \/1000x1000-000000-80- 0-0.jpg –
對不起,我還是不明白。你的意思是提取圖像(而不是'刪除')?請嘗試更好地解釋它。 – karliwson