PHP code example of rustem-kaimolla / kz-currency-rates

1. Go to this page and download the library: Download rustem-kaimolla/kz-currency-rates 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/ */

    

rustem-kaimolla / kz-currency-rates example snippets


use Currency\Requests\RateRequestBuilder;
use Currency\Parsers\XmlRateParser;
use Currency\Services\RateFetcher;
use GuzzleHttp\Client;

$builder = (new RateRequestBuilder())->forDate('12.05.2025');
$parser = new XmlRateParser();

$fetcher = new RateFetcher(
    $builder->build(),
    $parser
);

$rates = $fetcher->getAllRates();

foreach ($rates as $rate) {
    echo $rate->code . ': ' . $rate->rate . PHP_EOL;
}

$usd = $fetcher->getRate('USD');

echo "USD/KZT: {$usd->rate} ₸";

use Currency\Filters\MajorCurrencySpecification;

$spec = new MajorCurrencySpecification();

$majorRates = array_filter($rates, fn($rate) => $spec->isSatisfiedBy($rate));

foreach ($majorRates as $rate) {
    echo $rate->currency() . ': ' . $rate->value() . PHP_EOL;
}