PHP code example of dandelionmood / openexchangerates

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

    

dandelionmood / openexchangerates example snippets


// You'll need to get an app id.
define('OPENEXCHANGERATE_APP_ID', '123-123-123');

$oer = new OpenExchangeRates( OPENEXCHANGERATE_APP_ID );

// You'll get an object with all supported currencies
$currencies = $oer->currencies();

$oer = new OpenExchangeRates( OPENEXCHANGERATE_APP_ID );
$latest_rates = $eor->latest();

// With a paying plan, you can change base currency like this :
$latest_rates_in_euros = $eor->latest(array('base'=>'EUR'));

$one_month_ago = strftime('%Y-%m-%d', strtotime('- 1 month'));
$rates_last_month = $eor->historical($one_month_ago);

// You can list only certain currencies using additionnal parameters
$rates_last_month = $eor->historical(
	$one_month_ago,
	array('currencies'=>array('EUR','USD'))
);

$oer = new OpenExchangeRates(
	OPENEXCHANGERATE_APP_ID,
	OpenExchangeRates::PROTOCOL_HTTP
);

$oer = new OpenExchangeRates(
	OPENEXCHANGERATE_APP_ID,
	OpenExchangeRates::PROTOCOL_HTTP,
	OpenExchangeRates::HTTP_CLIENT_CURL
);