PHP code example of rubin / openexchangerates

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

    

rubin / openexchangerates example snippets


$api = new OpenExchangeRates\OpenExchangeRatesApi('{APP_ID}');

$api->setBase('EUR');

$api->setSymbols(['AMD', 'EUR']);

$api->setShowAlternative(true);

echo "Symbol\tRate\n";
foreach ($api->getLatest()->rates as $symbol => $rate) {
    printf("%s\t%s\n", $symbol, $rate);
}

echo "Symbol\tRate\n";
foreach ($api->getHistorical(new \DateTimeImmutable('2012-07-10'))->rates as $symbol => $rate) {
    printf("%s\t%s\n", $symbol, $rate);
}

echo "Symbol\tName\n";
foreach ($api->getCurrencies() as $symbol => $name) {
    printf("%s\t%s\n", $symbol, $name);
}

var_dump($api->getUsage());