Skip to content
Discussion options

You must be logged in to vote

Install the official PHP SDK via Composer:

composer require exchangerateapi/sdk

Usage:

use ExchangeRateAPI\ExchangeRateAPI;

$client = new ExchangeRateAPI('era_live_YOUR_KEY');

// Get exchange rate
$rate = $client->getRate('USD', 'EUR');
echo "1 USD = {$rate[0]['rate']} EUR\n";

// Convert amount
$result = $client->convert('USD', 'EUR', 100);
echo "\$100 = €{$result['result']}\n";

// Get historical rates
$history = $client->getHistoricalRates('USD', 'EUR', '30d');
foreach ($history['rates'] as $point) {
    echo "{$point['time']}: {$point['rate']}\n";
}

Requires only PHP 7.4+ with ext-curl and ext-json (both ship with standard PHP). No external Composer dependencies.

Get your free API k…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cahthuranag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant