PHP code example of rogerthomas84 / ohexchange

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

    

rogerthomas84 / ohexchange example snippets



OhExchange\OhExchangeException;
use OhExchange\OhExchangeService;

try {
    $models = OhExchangeService::getLatestRates();
    foreach ($models as $model) {
        echo $model->date->format('Y-m-d') . PHP_EOL;
        foreach ($model->rates as $currency => $exchange) {
            echo '  ' . $currency . ' -> ' . $exchange . PHP_EOL;
        }
        // Persist this model, using the date as a unique identifier.
    }
} catch (OhExchangeException $e) {
    echo 'Error:' . PHP_EOL;
    echo '  ' . $e;
}


$model = new \OhExchange\OhExchangeDto(); // Should be retrieved from your database.

$valueInUsd = $model->convertAmountFromTo(1, 'GBP', 'USD');