Jednoduchý príklad PHP implementácie pre spracovanie feed-u darcov z api.darujme.sk, bez validácie, exceptions, kontroly HTTP statusov a iných náležitostí. V tomto príklade sa používa: HTML 5.0 • PHP 7.2.0 • CSS: Bootstrap 4.5.0 • highlight.js 10.3.2
$feed = json_decode(file_get_contents('https://api.darujme.sk/v1/feeds/cee5e599-41f2-4b12-ad6e-3e5db38dd40b/donors/?per_page=500'), true);
$feed['response']['metadata']['total_amount'];
$feed['response']['metadata']['total'];
$feed['response']['donors'];
# | Name | Amount | Timestamp |
---|---|---|---|
1 | jenka Korbellová | 8.00 € | 03.08.2020 04:01 |
2 | Martinko Klingacik | 1.00 € | 03.08.2020 03:06 |
3 | jan balazia | 0.30 € | 29.07.2020 02:00 |
4 | Oľga Mičková | 2.00 € | 28.07.2020 09:35 |
5 | Ján Balažia | 108.36 € | 23.07.2020 10:05 |
6 | Alžbeta Mičková | 4.01 € | 22.07.2020 12:00 |
7 | Grétka Zelená | 1.00 € | 22.07.2020 12:00 |
8 | Zuzana Behríková | 12.00 € | 21.07.2020 02:01 |
9 | Jenka Korbellová | 2.00 € | 21.07.2020 12:45 |
10 | Peter Sopko | 1.00 € | 17.07.2020 03:35 |
11 | Jakub Dubec | 8.00 € | 17.07.2020 02:59 |
12 | Alzbeta Mickova | 3.00 € | 17.07.2020 02:56 |
13 | Peter Sopko | 2.00 € | 17.07.2020 02:52 |
foreach ($feed['response']['donors'] as $k => $v) {
echo '
<tr>
<td>' . ($k+1) . '</td>
<td>' . $v['donor_name'] . '</td>
<td class="text-right">' . number_format($v['amount'], 2) . ' € </td>
<td class="text-right">'
. date('d.m.Y h:i', strtotime($v['timestamp'])) .
'</td>
</tr>';
}