

To address this issue we will first create a way to change the numeric keys to some useful values. So the first step in building the solution is to find a way of exchanging the numerical keys with something more useful. At this point I should explain that each line of data would be returned as an array with numerical keys. We will use PHP file handling techniques to get data from the CSV file rather than downloading it. Output the results as either an associative array or a standard class object. Convert a single ‘base’ currency to multiple ‘targets’ or convert those ‘targets’ to the ‘base’ currency.ģ. Our objective is to develop a solution that would offer the following options:Ģ. But here our objective is to demonstrate how to read that data using PHP and return it as an array or a standard class objects.

Up to this point you should be able to download a CSV file with the data you desire, and use it that way in some solutions. This part suggests the format or the fields that should be returned in the data. That said, if you want to query multiple rates you could enter comma separated values like this: The first three letters here indicate the currency you are converting from, the next three indicate the currency you are converting to, and ‘=X’ presumably says you are querying an exchange rate. To begin, let’s try to understand the Yahoo! Finance URL. At this point it would be useful to learn about currency codes. This will tell us the last conversion rate for Eastern Caribbean Dollars (XCD) to United States Dollars (USD). It turns out that Yahoo! Finance has a CSV API that makes it very easy to get currency exchange rates (and stock quotes) in CSV format by using a URL like this one (and it’s FREE!):

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose.
