Exchange Rate API PHP Documentation

How To Use Our PHP Exchange Rates API

We offer an easy to use, accurate and reliable exchange rate API for PHP that's perfect for both personal and professional use.

Fetching exchange rates using our PHP currency conversion API is as easy as making GET requests. This means you can easily integrate our API into your PHP project however you'd prefer. No complex dependency hassles.

Our API returns JSON responses that are fast to parse and easily human-readable. PHP has high performance native library functions for handling JSON so you'll be able to access our data without much work at all.

For more details on the different types of request we support please see our Main Documentation.

Alternatively simply use the PHP library code below to get started as fast as you can copy & paste!

You'll need to sign up for a free account to receive your API key. Visit this link to get started.

Simple PHP Currency Conversion Example


// Fetching JSON
$req_url = 'https://v6.exchangerate-api.com/v6/YOUR-API-KEY/latest/USD';
$response_json = file_get_contents($req_url);

// Continuing if we got a result
if(false !== $response_json) {

    // Try/catch for json_decode operation
    try {

		// Decoding
		$response = json_decode($response_json);

		// Check for success
		if('success' === $response->result) {

			// YOUR APPLICATION CODE HERE, e.g.
			$base_price = 12; // Your price in USD
			$EUR_price = round(($base_price * $response->conversion_rates->EUR), 2);

		}

    }
    catch(Exception $e) {
        // Handle JSON parse error...
    }

}
							

This is a sample JSON response from a request with USD as the base currency code:

{
	"result": "success",
	"documentation": "https://www.exchangerate-api.com/docs",
	"terms_of_use": "https://www.exchangerate-api.com/terms",
	"time_last_update_unix": 1585267200,
	"time_last_update_utc": "Fri, 27 Mar 2020 00:00:00 +0000",
	"time_next_update_unix": 1585353700,
	"time_next_update_utc": "Sat, 28 Mar 2020 00:00:00 +0000",
	"base_code": "USD",
	"conversion_rates": {
		"USD": 1,
		"AUD": 1.4817,
		"BGN": 1.7741,
		"CAD": 1.3168,
		"CHF": 0.9774,
		"CNY": 6.9454,
		"EGP": 15.7361,
		"EUR": 0.9013,
		"GBP": 0.7679,
		"...": 7.8536,
		"...": 1.3127,
		"...": 7.4722, etc. etc.
	}
}

Please see our main documentation for further information on our different available request types & error response details.

Please email us if you'd like to submit a code example.