Everyone is interested in the stock markets at the moment and services such as Yahoo! Finance's stock quotes are a valuable resource for:
- would be investors
- stock market analysts
- programmers wanting to use stock quotes in their own application
...and all of those people may be interested to learn that Yahoo! Finance also supplies a currency conversion service.
Using the Yahoo! Finance Currency Conversion Web Page
Anyone who has used Yahoo! Finance stock quotes knows just how easy it is to obtain the information that they need, and the Yahoo! Finance Currency Converter is no different:
- the Yahoo! Finance Currency Converter can be found at http://finance.yahoo.com/currency
- the web page contains two drop down boxes:
- a drop down box for the currency to convert from
- a drop down box for the currency to convert to
- a input box for the amount of money to be converted
and, of course, a button to set the conversion into motion.
Downloading Yahoo! Finance Currency Conversion Data
The Yahoo! Finance currency conversion web page contains a link which, when clicked on, will load the data into a spreadsheet (such as Microsoft Excel or OpenOffice.org Calc); however (and this is where programmers may prick up their ears) the currency conversion data may also be accessed directly via the correct url. For example, to find the conversion rate from U.S. dollar to British pounds the url would be:
The above means : "convert from U.S. dollars(USD) to British pounds (GBP) using the most current conversion rate (l1) and output in csv format"; and armed with this information the programmer will be ready to start incorporating the data into an application - for example a PHP script.
Using Yahoo! Finance Currency Conversion Data in a PHP Script
A very simple PHP script is all that it takes to obtain the conversion rate, one that will format the url and then read the stream of data returned from the Yahoo! web site:
If this function is saved into a PHP library (for example yahoo_finance.php) then it can be called from any PHP web page:
And if this script is saved as yahoo_currency.php then it may be tested by calling it via a web browser, for example:
And then, of course, this PHP script can be used in an Ajax application.
Using Yahoo! Finance Currency Conversion Data in an Ajax Application
Once the PHP script is in place then that can be used as part of an Ajax application, for example one that allows the user to select currencies with radio buttons and then clicking a button to view the conversion rate:
As well as the Javascript code an HTML form will be required - one that defines the radio buttons for the currencies and that has a button that will call the above Javascript function:
Conclusion
With Yahoo! Finance anyone can easily access the on-line currency converter or, with a little more effort, a programmer can use that data in their own applications - all through the power of Javascript and PHP.
Additional Reading
Accessing Yahoo! Finance from PHP
Using Yahoo! Financial Stock Quotes
An Introduction to Google Finance