PHP Classes

File: example.php

Recommend this page to a friend!
  Classes of Dave Smith   PHP Exchange Rates   example.php   Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Example Usage
Class: PHP Exchange Rates
Get currency exchange rates from ExchangeRates API
Author: By
Last change:
Date: 3 years ago
Size: 1,107 bytes
 

Contents

Class file image Download
<?php
/*
example usage
exchangeRates ver 1.0

You must get an API key from https://exchangeratesapi.io/pricing/
and enter it in the exchangerates.class.php file

For complete documentation on each endpoint and available paramaters
see https://exchangeratesapi.io/documentation/
*/

//turning off low level notices
error_reporting(E_ALL ^ E_NOTICE);

//instantiate the class
require('exchangerates.class.php');
$exchange = new exchangeRates();

//get exhange rate for USD to GBP,JPY,EUR
$exchange->setEndPoint('latest');
$exchange->setParam( 'base', 'USD' );
$exchange->setParam( 'symbols', 'GBP,JPY,EUR' );

//get response from API
$exchange->getResponse();

//dump response object
echo '<strong>Current Rates</strong>';
echo
'<pre>';
var_dump($exchange->response);
echo
'</pre>';

//get historical rates from Dec 24 2013
$exchange->setEndPoint('historical', '2013-12-24');

//get response from API
$exchange->getResponse();

//dump response object
echo '<strong>Historical Rates</strong>';
echo
'<pre>';
var_dump($exchange->response);
echo
'</pre>';

die;
?>