forked from coinwink/cryptocurrency-logos
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_logos_64x64.php
More file actions
38 lines (26 loc) · 938 Bytes
/
get_logos_64x64.php
File metadata and controls
38 lines (26 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
// Get data for all coins from Coinmarketcap API
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://s2.coinmarketcap.com/generated/search/quick_search.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
// Replace quotes that might break the json decode
$output = str_replace("'", "", $output);
// Decode json data to use as a php array
$outputdecoded = json_decode($output, true);
foreach ($outputdecoded as $coin) {
// Get CMC ID
$cmcid = $coin["id"];
// Get public ID
$pubid = $coin["slug"];
echo($cmcid);
echo($pubid);
// Using the CMC ID build the link for logo
$file_url = "https://s2.coinmarketcap.com/static/img/coins/64x64/" . $cmcid . ".png";
// Get file logo, rename it and save
$image = file_get_contents($file_url);
$img_path = "coins/64x64/" . $pubid . ".png";
file_put_contents($img_path, $image);
}
?>