PHP code example of richardds / ecb-api

1. Go to this page and download the library: Download richardds/ecb-api 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/ */

    

richardds / ecb-api example snippets




use Richardds\ECBAPI\ECBConverter;

$converter = new ECBConverter();

echo $converter->toEuro(150, 'USD', 3);
echo $converter->toForeign(150, 'USD');
print_r($converter->toForeign(150, ['EUR', 'USD', 'CHF', 'RUB', 'CZK'])) . PHP_EOL;



use Richardds\ECBAPI\ECBConverter;

$converter = new ECBConverter();

$references = $converter->list(true);

foreach ($references as $code => $rate) {
    if ($code === 'EUR') {
        continue;
    }

    printf("1.00 EUR = %.2f %s\n1.00 %s = %.2f EUR\n", $rate, $code, $code, (1 / $rate));
}
text
1.00 EUR = 1.18 USD
1.00 USD = 0.85 EUR
1.00 EUR = 130.31 JPY
1.00 JPY = 0.01 EUR
1.00 EUR = 1.96 BGN
1.00 BGN = 0.51 EUR
1.00 EUR = 26.15 CZK
1.00 CZK = 0.04 EUR
...