After searching a lot, found this.
// Fetching JSON
$req_url = 'https://api.exchangerate-api.com/v4/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_object = json_decode($response_json);
// YOUR APPLICATION CODE HERE, e.g.
$base_price = 12; // Your price in USD
$EUR_price = round(($base_price * $response_object->rates->EUR), 2);
}
catch(Exception $e) {
// Handle JSON parse error...
}
}
This is working fine.
The snippet is from: https://www.exchangerate-api.com/docs/php-currency-api