PHP code example of zdenekgebauer / cnb-client
1. Go to this page and download the library: Download zdenekgebauer/cnb-client library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
zdenekgebauer / cnb-client example snippets
use \ZdenekGebauer\CnbClient\Client;
use \ZdenekGebauer\CnbClient\Exception;
$client = new Client();
// retrieve current rate
try {
$rate = $client->getRate('USD'));
} catch (\ZdenekGebauer\CnbClient\Exception) {
// exception about unsupported currency or failed connection
}
var_dump($rate->currency) // HUF
var_dump($rate->quantity) // 100
var_dump($rate->rate) // 6.154 means 6.154 CZK/100 HUF
var_dump($rate->date) // date of rate from API
// retrieve rate for specific date
$rate = $client->getRate('HUF', new \DateTime('2022-06-22')));