Forum Moderators: coopster
I'd like to be able to have this value in the text file updated via a php script which I could then set to run hourly. Does anyone know of a good source of this conversion rate? At the moment i have to manually update the text file on a daily basis, which is far from perfect ;)
Thanks,
Don
[ecb.int...]
Is there an accepted way to grab an XML result, such as the above, and parse the results into an array? I'm trying to do so using NuSoap but it just isn't making any sense.
Any pointers much appreciated,
Don
Have a look at the PHPXPath project on Sourceforge:
[sourceforge.net...]
If you download phpxpath into a directory; you can get the EUR:GBP exchange rate using the following code:
<?php
require("XPath.class.php");
$xp = new XPath();
$xp->importFromFile("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
$EUR_GBP_RATE = $xp->getAttributes("//Cube[@currency='GBP']","rate");
echo($EUR_GBP_RATE);?>
Thats exactly the kind of thing I was looking for. Thinking it would be much more complex, I just finished (5 mins ago) writing the following script to get the data via str_replace:
$euroinfo = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml'; $fp = fopen($euroinfo, "r"); $data = ""; while(!feof($fp)) { $data .= fgets($fp, 4096); if (preg_match ('/GBP/', $data)) { $rate = $data; } $data = ''; } $rate = str_replace("<Cube currency='GBP' rate='", '', $rate); $rate = str_replace("'/>", '', $rate); $rate = str_replace("\t", '', $rate); The XPath method is much tidier! :)
Don