Skip to content

Instantly share code, notes, and snippets.

@platinize
Created April 6, 2018 12:44
Show Gist options
  • Save platinize/f90047e2935750ee829244072b41de5e to your computer and use it in GitHub Desktop.
Save platinize/f90047e2935750ee829244072b41de5e to your computer and use it in GitHub Desktop.
curl
<?php
$date = (isset($_POST['date']))? date('d.m.Y',strtotime($_POST['date'])) : date('d.m.Y',strtotime('-3 day'));
$url = 'https://api.privatbank.ua/p24api/exchange_rates?date='.$date;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($curl);
curl_close($curl);
unset($curl);
$xml = new SimpleXMLElement($page);
?>
<p><?=$date?></p>
<table border="1" cellspacing="0" cellpadding="5">
<tr>
<td>Валюта</td>
<td>Продажа</td>
<td>Покупка</td>
</tr>
<?php foreach($xml as $exchangerate): ?>
<tr>
<td><?=$exchangerate['baseCurrency'].'/'.$exchangerate['currency'];?></td>
<td><?=$exchangerate['saleRateNB'];?></td>
<td><?=$exchangerate['purchaseRateNB'];?></td>
</tr>
<?php endforeach; ?>
</table>
<form method="POST">
<input type="date" name="date" value="<?=date('Y-m-d',strtotime('-3 day'));?>">
<input type="submit" name="confirm" value="Выбрать">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment