Created
March 27, 2011 12:05
-
-
Save solon/889148 to your computer and use it in GitHub Desktop.
Print out the current Euro value for a currency, based on ECB daily rates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // for a list of all supported currencies, view the source code of this page: | |
| // http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml | |
| $x = simplexml_load_file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml"); | |
| function getEuroRate($symbol,$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',$x) . " GBP\n"; | |
| echo "1 EUR = " . getEuroRate('USD',$x) . " USD\n"; | |
| echo "1 EUR = " . getEuroRate('CAD',$x) . " CAD\n"; | |
| echo "1 EUR = " . getEuroRate('JPY',$x) . " JPY\n"; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment