PHP code example of jdrda / cnb-currency-converter
1. Go to this page and download the library: Download jdrda/cnb-currency-converter 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/ */
jdrda / cnb-currency-converter example snippets
nbCurrencyConverter\CnbCurrencyConverter;
$converter = new CnbCurrencyConverter();
// Official CNB quote: 1 EUR = 24.340 CZK, 100 JPY = 13.249 CZK, etc.
echo $converter->rate('EUR')->formatQuote();
// Normalized CZK value for exactly one unit of a currency.
echo $converter->czkPerUnit('JPY'); // 0.13249 when CNB quotes 100 JPY = 13.249 CZK
// Convert EUR to USD through CZK.
echo $converter->convert(100, 'EUR', 'USD');
// Convert JPY to EUR through CZK. Quoted amounts such as 100 JPY are handled correctly.
echo $converter->convert(10000, 'JPY', 'EUR');
use CnbCurrencyConverter\CnbCurrencyConverter;
$converter = new CnbCurrencyConverter('2026-05-06');
// Uses the CNB URL with ?date=06.05.2026
echo $converter->rate('USD')->formatQuote();
use CnbCurrencyConverter\CnbCurrencyConverter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
$cache = new FilesystemAdapter('cnb_currency_converter');
$converter = new CnbCurrencyConverter(null, $cache);
$converter = new CnbCurrencyConverter(null, $cache, 3600); // one hour
use CnbCurrencyConverter\CnbCurrencyConverter;
$converter = new CnbCurrencyConverter();
$amount = $converter->convert(100, 'EUR', 'USD', 2);
use CnbCurrencyConverter\CnbCurrencyConverter;
final class PriceController
{
private $converter;
public function __construct(CnbCurrencyConverter $converter)
{
$this->converter = $converter;
}
}