Page 1 of 1
Getting Current Currency Exchane Rate in PHP
Posted: Thu Dec 18, 2008 12:11 am
by jithkutty
how can we get current exchange rate Indian money to usd?
anybody can help me?
thanks
Re: Getting Current Currency Exchane Rate in PHP
Posted: Thu Dec 18, 2008 8:37 am
by volomike
Use Curl to hit this URL:
http://www.google.com/search?hl=en&q=IN ... tnG=Search
Now, parse the result for '<h2 class="r">' up to '</h2>'. Next, run the result through strip_tags() and then parse further for the value you need.
Code: Select all
preg_match('@<h2 class="r">(.*?)</h2>@s',$sResult,$asMatches);
$sResult = strip_tags($asMatches[1]);
If you don't need this to be 100% accurate, then I highly advise you to cache this value, say, every 4 to 12 hours, in shared memory on the server. This keeps Google off your scent and also speeds up your website.
Re: Getting Current Currency Exchane Rate in PHP
Posted: Thu Dec 18, 2008 9:55 am
by pickle
Look up web services - I know there's a web service out there that is much cleaner than parsing a web page.
Re: Getting Current Currency Exchane Rate in PHP
Posted: Fri Dec 19, 2008 9:50 pm
by josh
Isn't this what the $ syntax is for? Just kidding...
Re: Getting Current Currency Exchane Rate in PHP
Posted: Mon Dec 22, 2008 3:35 am
by panic!
There's many far better ways that screenscraping Google..
for example:
http://download.finance.yahoo.com/d/quo ... s=EURGBP=X
...merry christmas

Re: Getting Current Currency Exchane Rate in PHP
Posted: Thu Jan 08, 2009 7:46 am
by anjanesh