Skip to content

Instantly share code, notes, and snippets.

@solon
Created March 27, 2011 04:39
Show Gist options
  • Select an option

  • Save solon/888917 to your computer and use it in GitHub Desktop.

Select an option

Save solon/888917 to your computer and use it in GitHub Desktop.
Print out the current Euro value for a currency, based on ECB daily rates
<?php
// for a list of all supported currencies, view the source code of this page:
// http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml
function getEuroRate($symbol) {
$xml = simplexml_load_file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
$xml->registerXPathNamespace("ecb", "http://www.ecb.int/vocabulary/2002-08-01/eurofxref");
$array = $xml->xpath("//ecb:Cube[@currency='".$symbol."']/@rate");
$rate = (string) $array[0]['rate'];
return $rate;
}
echo "1 EUR = " . getEuroRate('GBP') . " GBP\n";
echo "1 EUR = " . getEuroRate('USD') . " USD\n";
echo "1 EUR = " . getEuroRate('CAD') . " CAD\n";
echo "1 EUR = " . getEuroRate('JPY') . " JPY\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment