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:
How do we get Google's "Euro to Pound" conversion rate?
We want to be able to update our website dynamically with the Euro price as it seems to change often.
We show the price, and say "in euros it is approx... X".
We want this euro price to be based on the conversion rate on Google, wthout having to keep an eye on the rate outselves.
How is it done?
We show the price, and say "in euros it is approx... X".
We want this euro price to be based on the conversion rate on Google, wthout having to keep an eye on the rate outselves.
How is it done?
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?
Not Google, but the European Central Bank has a free feed that gets updated daily.
http://www.ecb.europa.eu/stats/eurofxre ... -daily.xml
http://www.ecb.europa.eu/stats/eurofxre ... -daily.xml
-
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?
I've no idea how to get into XML and export to a PHP variable. Can you please advise?
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?
Use a remote call to get the XML -- Guzzle, cURL, file_get_contents, doesn't really matter -- and then parse it with SimpleXMLElement.
-
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?
Ok. It's all a little beyond me.
I use file_get_contents for another purpose, but it just finds a particular numeric value and passes that to a $matches[0] variable.
I use file_get_contents for another purpose, but it just finds a particular numeric value and passes that to a $matches[0] variable.
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?
I'm trying.... but am def going wrong
Code: Select all
$xmleuro = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
$contentseuro = file_get_contents($xmleuro);
$eurofind = new SimpleXMLElement($xmleuro);
echo $Cube[5]->currency;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?
You've got nested Cube elements which you need to traverse. Building off your example,
Code: Select all
$xmleuro = "http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";
$contentseuro = file_get_contents($xmleuro);
$eurofind = new SimpleXMLElement($xmleuro);
echo $eurofind->Cube[0]->Cube[0]->Cube[5]->currency;Re: How do we get Google's "Euro to Pound" conversion rate?
That's really quick and dirty, though, and quite brittle. Look into XPath and namespaces. I need to run off to the office now but will check back later.
-
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?
My local version doesn't like:
Code: Select all
$eurofind = new SimpleXMLElement($xmleuro);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?
What does that even mean?simonmlewis wrote:My local version doesn't like:
Code: Select all
$eurofind = new SimpleXMLElement($xmleuro);
Re: How do we get Google's "Euro to Pound" conversion rate?
Using the XPath method I mentioned earlier, you'd do something like this:
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"]');
echo $cube[0]['rate'];
-
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?
Ok. I think I may have done something the wrong way around.
I need to get the value to convert GBP to EURO?
And to DOLLAR.
I need to get the value to convert GBP to EURO?
And to DOLLAR.
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?
You've got EURO to GBP, which means you also have GBP to EURO. You've also got EURO to USD. You can math it out easily enough.
-
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?
To get a euro from gbp you do Pound Euro. So how do I say "£55.00 i approx x Euro"? Without knowing it's around 1.17 euro to the pound?
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?
But you do know that. You have the Euro to Pound conversion rate.