How do we get Google's "Euro to Pound" conversion rate?
Moderator: General Moderators
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do we get Google's "Euro to Pound" conversion rate?
Sure.... but I don't have the Euro value.......
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do we get Google's "Euro to Pound" conversion rate?
Erm, division? 1 EUR = 0.855 GBP, therefore 1 GBP = 1/0.855 EUR = 1.16959 EUR.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do we get Google's "Euro to Pound" conversion rate?
Code: Select all
$xml = file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
$sxe = new SimpleXMLElement($xml);
$sxe->registerXPathNamespace('r', 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref');
$sxe->registerXPathNamespace('g', 'http://www.gesmes.org/xml/2002-08-01');
$cube = $sxe->xpath('r:Cube/r:Cube/r:Cube[@currency="GBP"]');
$eurocheck = $cube[0]['rate'];
echo "$row->price <b>$eurocheck</b>";
$europrice = $row->price / $euroeheck;Yet if I echo the second line from botton, it displays the correct amounts.
It's just the dividing that wont work.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do we get Google's "Euro to Pound" conversion rate?
Even with the $euroeheck typo corrected?
Re: How do we get Google's "Euro to Pound" conversion rate?
Ah, I see what's happening. $eurocheck is an instance of SimpleXMLElement. You need to cast it to a string before using it.
Code: Select all
<?php
$xml = file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
$sxe = new SimpleXMLElement($xml);
$sxe->registerXPathNamespace('r', 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref');
$sxe->registerXPathNamespace('g', 'http://www.gesmes.org/xml/2002-08-01');
$cube = $sxe->xpath('r:Cube/r:Cube/r:Cube[@currency="GBP"]');
$eurocheck = (string) $cube[0]['rate'];
$europrice = 100 / $eurocheck;
echo $europrice;
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do we get Google's "Euro to Pound" conversion rate?
actually yes.
[text]14.99 0.85500
Warning: Division by zero in C:\xampp\phpMyAdmin\site-wide\includes\product.inc on line 559[/text]
[text]14.99 0.85500
Warning: Division by zero in C:\xampp\phpMyAdmin\site-wide\includes\product.inc on line 559[/text]
Code: Select all
Code: Select all
$xml = file_get_contents('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
$sxe = new SimpleXMLElement($xml);
$sxe->registerXPathNamespace('r', 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref');
$sxe->registerXPathNamespace('g', 'http://www.gesmes.org/xml/2002-08-01');
$cube = $sxe->xpath('r:Cube/r:Cube/r:Cube[@currency="GBP"]');
$eurocheck = $cube[0]['rate'];
echo "$row->price <b>$eurocheck</b>";
>> line 559 >> $europrice = $row->price / $eurocheck;Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do we get Google's "Euro to Pound" conversion rate?
I trust you saw the post above and this is sorted now?
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do we get Google's "Euro to Pound" conversion rate?
Sorry you've lost me now.
$europrice = $row->price / 0.85 (roughly).
So how do I reach that from the code you sent?
$europrice = $row->price / 0.85 (roughly).
So how do I reach that from the code you sent?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do we get Google's "Euro to Pound" conversion rate?
So Europrice becomes 116.95906432749.
I am missing something here. How do I go from 116.95, and take that and use it to convert £15 into Euros ?
I am missing something here. How do I go from 116.95, and take that and use it to convert £15 into Euros ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do we get Google's "Euro to Pound" conversion rate?
Instead of using 100, which I needed to use for the sake of example, you'd use your $row->price
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do we get Google's "Euro to Pound" conversion rate?
Oh I see.
So without duplicating the code and pulling it in twice, how would I use it for USD ?
So without duplicating the code and pulling it in twice, how would I use it for USD ?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: How do we get Google's "Euro to Pound" conversion rate?
Might be worth setting up the XML parsing to be run on a schedule. Once a day you get the latest rates, parse them, and store in your DB. Then you can just reference the stored values to perform your calculations.
as for
as for
start using functions to keep your code DRY. Ultimately you'll want to wrap those into classes, but one step at a time.So without duplicating the code
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: How do we get Google's "Euro to Pound" conversion rate?
Yes I think a cron job would be better. That way if their page takes an age to load, it doesn't matter!
We already have a cron that runs regularly, so I could pop it into the same one.
We already have a cron that runs regularly, so I could pop it into the same one.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.