Getting Current Currency Exchane Rate in PHP

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
jithkutty
Forum Newbie
Posts: 1
Joined: Thu Dec 18, 2008 12:07 am

Getting Current Currency Exchane Rate in PHP

Post by jithkutty »

how can we get current exchange rate Indian money to usd?
anybody can help me?
thanks
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: Getting Current Currency Exchane Rate in PHP

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Getting Current Currency Exchane Rate in PHP

Post by pickle »

Look up web services - I know there's a web service out there that is much cleaner than parsing a web page.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Getting Current Currency Exchane Rate in PHP

Post by josh »

Isn't this what the $ syntax is for? Just kidding...
User avatar
panic!
Forum Regular
Posts: 516
Joined: Mon Jul 31, 2006 7:59 am
Location: Brighton, UK

Re: Getting Current Currency Exchane Rate in PHP

Post 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 :)
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Re: Getting Current Currency Exchane Rate in PHP

Post by anjanesh »

Post Reply