Hi,
Here is a simple PHP code, using which you can get the live currency Value from yahoo finance ( http://finance.yahoo.com/ )
In this example i am getting the value of US Dollar in Indian Rupees.
<?php $from = 'USD'; /*change it to your required currencies */ $to = 'INR'; $url = 'http://finance.yahoo.com/d/quotes.csv?e=.csv&f=sl1d1t1&s='. $from . $to .'=X'; $handle = @fopen($url, 'r'); if ($handle) { $result = fgets($handle, 4096); fclose($handle); } $allData = explode(',',$result); /* Get all the contents to an array */ $dollarValue = $allData[1]; echo 'Value of $1 in Indian Rupees is Rs. '.$dollarValue; ?>
Recently this code also got published here also

Thanks for script I was looking for it long time
Too good….after a long search I’ve got this…Thanx a lot!!!
Its realy great help.
Thanks
Thank you
But notice that the url has changed from
“http://finance.yahoo.com”
to
“http://download.finance.yahoo.com”
Can any one post the above PHP in javascript….
no
hi , the code you have mentioned to convert currenct to Rupee but i want only two decimal points not more than that for that how to do that.. ?????
Hi you can use PHP’s round function for this. For the above case use
round($dollarValue, 2)
It will serve your purpose.
If I want four digits after the decimal point., What i have to do?
This is really helpfull and save my time.
Thanks
HI HOW USE IT AND SEND ME A LINK FOR DOWNLODE
THANKS
Great script, thanks!! But I want to know if these currency rates have a delay? how much time is it?
I think there will be no delay as such.
As we are getting the value from finance.yahoo.com, and this will have most latest updated.
Awesome. You don’t know how hard it’s been finding a free/reliable web service for this. Cheers!
how can i send amount to covert in the url. for example amount unit more than 1.
Any how you are getting the unit price from the above code. Multiply with the whatever number you want to get the actual value.
which is not entirely correct, because there are currencies out there which have a greater difference in sum, as yahoo finance rounds it to 4 decimals, which will give a different outcome. BYR Belarus Ruble has such a big difference if queried by 1 or at a 1000 pieces, 0.003 if you query 1, 0.2555 if you query 1000. Didn’t figure out how to query another base sum though 😦
and I did found the solution for that little problem, so I needed to share 🙂
just reverse the query – instead of BYREUR=X use EURBYR=X and reverse your calculation if you reverse the query.
thanks for this great little script btw. 😉
Hey, Sridhar, an incredible job with that piece of code.
I’m the person who asked you permission to adapt the code as a plugin for the DokuWiki (http://www.dokuwiki.org/) CMS. Things go OK so far but since I haven’t heard from you I thought my mail could have been filtered as SP*M and decided to let you know by this media.
The adapted code is here: http://www.dokuwiki.org/plugin:gil with proper credits.
Thanks again for a very interesting work.
Thanx dude., i was looking for this., gr8 work
Thanks for this, works great.
I’ve come up against Yahoo’s error 999 (too many requests). Does anyone know how often you’re allowed to query this service?
Very nice work! Thanks a lot.
Steve, setup a cron service and get silent the quotes every X minutes and then submit it to a db for not overcharge the Y! server.
thanks. it saves my job!
hey…..
super yarr…..
That’s Nice!………. 🙂
Hey, nice work with this! But what worries me is when yahoo! decides to change their html or urls or whatever. After a lot of googling I found this site, http://www.exchangerate-api.com which looks professional and easy to use.
Thank u soo much u saved my day
HI PLZ GIVE ME DETAILS ON KANDEKARGROUP@GMAIL.COM HOW TO USE, DOWNLOADS…
THANKS
Great ! Can we get live stock quotes .. do u have a code in php ….
Thanks in advance
Thank you kindly! I’d been using a nasty data-scape till now.
Thanks very much i was searching this script from a long time ……….
great
thanks for the script. its very helpful. 🙂
This rate is live ?????
plz reply me as early as possible
yes. Its is live from yahoo finance
thank U for ur replay
this code is vrey use ful for me
in ecommners application
thank U very much…………………
Thanks 🙂
really very nice code. this is very helpful for me to deliver my project. Best of luck and god bless you.
Thanks! Will use it on client project.
I tweaked the code, to make it ‘less hassle’
http://pastie.org/1504759
Hello,
I want to convert $175 to IDR , but i dont know i must entered value (175) into code.
Please Help me
Thanks
Sir, can i implement the same using javascript. ? if so where can i get the code?
thanks in advance.
Hi
i am not understand what is PHP kindly tell me how to use this code for live currency rate.
thankz a lot
Thanks a lot, this is exactly what we looking for! 2008-2012, yahoo still providing the nice service, hope it will not give up for at least another 50 years 😉
Thanks. This works!!
Very useful script. But can you tell me where i put my database amount. I want my own amount?
Please tell me as soon as possible.
Thanks
i am very lucky i got this script on my first search
Thank you so much ! Works great. I was searching this script from a long time
Thanks again for a very interesting work.
This works brilliantly, I’m using it to convert GBP to USD for a feed for google products! Thanks!
Thanks for your help
but this url fetches rate 2 day back
Thx man, you are the best! 🙂
Thanks a lot… friend
Get live Yahoo exchange rates in PHP
[PHP]
$from = ‘CAD’; /*change it to your required currencies */
$to = ‘USD’;
$url = simplexml_load_file(‘http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%20in%20(%22′.$from.”.$to.’%22)&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys’);
$rate = ($url->results->rate->Rate);
$rate = round($rate, 2);
echo $rate;
?>[/PHP]
Can I Implement This Code In My Site For Commercial Use ?
Yes.
thanks. this is just what i need.
Thank You Very Much ! I was searching a solution for this.
We’ve been scraping Yahoo for a while but found that a) there rates are not very consistent compared to other providers and b) if you need to request rates more than every 10-minutes, the API starts blocking your requests after a while.
I’d recommend going with a freemium provider instead. Two good ones I know are http://www.currencylayer.com and http://www.openexchangerates.org
Thanks. It’s the script i’m looking for. Very simple and effective.
It is possible add more 2 currencies for conversion in the url? I need to convert from USD to 3 different currencies.
Thanks, its work!