<

Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

Getting Currency Exchange Rates with PHP and Yahoo! Finance CSV API

Published on
29,116 Points
22,916 Views
2 Endorsements
Last Modified:
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.

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!):

http://finance.yahoo.com/d/quotes.csv?s=XCDUSD=X&f=sl1d1t1

Open in new window


This will tell us the last conversion rate for Eastern Caribbean Dollars (XCD) to United States Dollars (USD). At this point it would be useful to learn about currency codes.

Breaking down the URL

To begin, let’s try to understand the Yahoo! Finance URL.

URL Start

http://finance.yahoo.com/d/quotes.csv?s=

Open in new window


Lookup values (or stock symbols)

XCDUSD=X

Open in new window


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. That said, if you want to query multiple rates you could enter comma separated values like this:

XCDUSD=X,XCDGBP=X,XCDEUR=X

Open in new window


Result Format

&f=sl1d1t1

Open in new window


This part suggests the format or the fields that should be returned in the data. Let’s describe each part in turn.

s       =       the Symbol (lookup value) queried.
l1      =       the last exchange value
d1      =       the last exchange date
t1       =       the last exchange time

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. 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.

Building the PHP Solution

Our objective is to develop a solution that would offer the following options:
1.      Lookup or query multiple currencies
2.      Convert a single ‘base’ currency to multiple ‘targets’ or convert those ‘targets’ to the ‘base’ currency.
3.      Output the results as either an associative array or a standard class object.

We will use PHP file handling techniques to get data from the CSV file rather than downloading it. At this point I should explain that each line of data would be returned as an array with numerical keys. So the first step in building the solution is to find a way of exchanging the numerical keys with something more useful.

Adding Useful Array Keys

To address this issue we will first create a way to change the numeric keys to some useful values. This helps us crate our associative array later on, and it also makes more sense if we convert the results to a standard class object.

<?php
/*
* @function: add_cx_keys( $array )
*/
function add_cx_keys( $array ) {
	/*
	* @keys: Define the desired array keys in an array
	*/
	$target_keys = array( 'cx_name', 'cx_code', 'cx_test', 'cx_rate', 'cx_date', 'cx_time' );
	$i = 0;
	foreach($target_keys as $key) {
		$arrOutput[$key] = $array[$i];
		$i++;
	}
	return $arrOutput;
}
?>

Open in new window


Converting Arrays to Objects

To be able to make our results into an object later on, we would need a technique to convert arrays to objects. This pair of functions would do that very nicely.

<?php
/*
* @function: make_array_object() | array_to_object() - convert an associative array to an object
*/
function make_array_object( $array ) {
	$object = new stdClass();
	return array_to_object( $array, $object );
}

function array_to_object( $arr, &$obj ) {
	foreach( $arr as $key=>$val )
	{
		if( is_array( $val ) )
		{
			$obj->$key = new stdClass();
			array_to_object( $val, $obj->$key );
		}
		else
		{
			$obj->$key = $val;
		}
	}
	return $obj;
}
?>

Open in new window


Getting those Exchange Rates

The functions defined so far, would play supporting roles in the overall solution. We now turn to the function that really puts this solution into gear, and delivers our desired results.

<?php
function get_exchange_rates( $home_currency, $convert_to = '', $additional_targets = array(), $output_type = '' ) {
	/*
	* @default_targets: A list of default (popular|moset used) currencies
	*/
	$default_targets = array( 
		'USD'=>'US Dollar',
		'EUR'=>'Euro',
		'GBP'=>'British Pound',
		'AUD'=>'Australian Dollar',
		'CAD'=>'Canadian Dollar',
		'CHF'=>'Swiss Franc',
		'INR'=>'India Rupee',
		'CNY'=>'Chinese Yuan Renminbi',
		'NZD'=>'New Zealand Dollar',
		'JPY'=>'Japan Yen',
		'BBD'=>'Barbados Dollar',
		'BSD'=>'Bahamas Dollar',
		'BZD'=>'Belize Dollar',
		'GYD'=>'Guyana Dollar',
		'JMD'=>'Jamaica Dollar',
		'TTD'=>'Trinidad and Tobago Dollar',
		'XCD'=>'Eastern Caribbean Dollar'
	);
	
	/*
	* @additional_targets: Add more currencies if available
	*/
	if( !empty( $additional_targets ) && is_array( $additional_targets ) ) {
		$target_currencies = array_merge( $default_targets, $additional_targets );
	} else {
		$target_currencies = $default_targets;
	}
	
	/*
	* @unset: Remove home currency from targets
	*/
	if( array_key_exists( $home_currency, $target_currencies ) ) {
		unset( $target_currencies[$home_currency] );
	}
	
	/*
	* @loop: Loop through the targets and perform lookup on Yahoo! Finance
	*/
	foreach( $target_currencies as $code => $name ) {
		/*
		* @url: Get the URL for csv file at Yahoo API, based on 'convert_to' option
		*/
		switch( strtoupper( $convert_to ) ) {
			case 'H': /* Converts targest to home */
				$url = sprintf( "http://finance.yahoo.com/d/quotes.csv?s=%s%s=X&f=sl1d1t1", $code, $home_currency );
			break;
			case 'T': /* Converts home to targets */
			default:
				$url = sprintf( "http://finance.yahoo.com/d/quotes.csv?s=%s%s=X&f=sl1d1t1", $home_currency, $code );
			break;
		}
		
		/*
		* @fopen: open and read API files
		*/
		$handle = @fopen( $url, 'r' );
		if ( $handle ) {
			$result = fgets( $handle, 4096 );
			fclose( $handle );
		}
		
		/*
		* @output: Create output array and add currency code and descriptive (Country) name
		*/
		$arrOutput[$code] = explode( ',', $result );
		array_unshift( $arrOutput[$code], $code ); /* Add the code */
		array_unshift( $arrOutput[$code], $name ); /* Add the name */
		
		/*
		* @keys: Substitute numerical keys with user friendly ones
		*/
		$arrOutput[$code] = add_cx_keys( $arrOutput[$code] );
	}
	
	/*
	* @object: Convert array to object if required
	*/
	if( strtoupper( $output_type ) == 'OBJECT' ) {
		$arrOutput = make_array_object( $arrOutput );
	}
	
	/*
	* @return: Return the output array or object
	*/
	return $arrOutput;
} 
?>

Open in new window


You would notice that I done considerable commenting within the code for this function. Those comments should pretty much explain what it does, and how. Just put this function together with the others, stick them into your web project and you have the complete setup to grab those exchange rates.

Now let us look at a typical implementation and the parameters we can pass to our function.

<?php $rates = get_exchange_rates( $home_currency, $convert_to = '', $additional_targets = array(), $output_type = '' ); ?>

Open in new window

 

The function takes four (4) parameters, which are detailed as follows:

$home_currency
(string) (required) . The currency code of your choice, and for which you wish to get exchange rates.
Default: None

$convert_to
(string) (optional). Determines whether to perform conversion to Home Currency (H) or Target Currencies (T). You can also pass ‘null’ to this parameter if you want to access $additional_targets.
Options: ‘H’, ‘T’
Default: ‘T’.

$additional_targets
(array) (optional). Add additional target currencies if desired. You can also pass ‘null’ to this parameter if you want to access $output_type.
Default:  array()

$output_type
(string) (optional). This determines whether to output associative array or standard class object.
Options: ‘ARRAY_A’, ‘OBJECT’
Default: ‘ARRAY_A’

Examples of Use

<?php $rates = get_exchange_rates( ‘XCD' ); ?>

Open in new window


Returns the rates for Eastern Caribbean Dollars in the default list, as an associative array.

<?php $rates = get_exchange_rates( ‘XCD', ‘H' ); ?>

Open in new window


Returns the rates in Eastern Caribbean Dollars for each of the currencies in the default list.

<?php $rates = get_exchange_rates( ‘XCD', null, array( ‘EGP'=>'Egypt Pound' ), ‘OBJECT' ); ?>

Open in new window


Returns the rates for Eastern Caribbean Dollars in the default currencies and Egypt Pounds as an object.

<?php
foreach( $rates as $rate ) {
	echo '<p>' . $rate['cx_name'] . ' ('. $rate['cx_rate'] . ')</p>';
}?>

Open in new window


Prints the name and rate for each target currency from an array.

<?php
foreach( $rates as $rate ) {
	echo '<p>' . $rate->cx_name . '('. $rate->cx_rate . ')</p>';
}
?>

Open in new window


Prints the name and rate for each target currency from an object.

<?php echo $rates['USD']['cx_name']; ?>

Open in new window


Prints the currency name for USD from an array.

<?php echo $rates->EUR->cx_name; ?>

Open in new window



Prints the currency name for EUR from an object.


Putting it all Together

For convenience, let’s put the complete code for this solution together.  For your convenience or preference you might adjust the values of the default_targets array. And there you go! I hope you find this useful for your projects, and have fun getting those exchange rates.

<?php
/*
* @function: get_echange_rates() - get currency echanges rates using Yahoo! Finance CSV API
*/
function get_exchange_rates( $home_currency, $convert_to = '', $additional_targets = array(), $output_type = '' ) {
	/*
	* @default_targets: A list of default (popular|moset used) currencies
	*/
	$default_targets = array( 
		'USD'=>'US Dollar',
		'EUR'=>'Euro',
		'GBP'=>'British Pound',
		'AUD'=>'Australian Dollar',
		'CAD'=>'Canadian Dollar',
		'CHF'=>'Swiss Franc',
		'INR'=>'India Rupee',
		'CNY'=>'Chinese Yuan Renminbi',
		'NZD'=>'New Zealand Dollar',
		'JPY'=>'Japan Yen',
		'BBD'=>'Barbados Dollar',
		'BSD'=>'Bahamas Dollar',
		'BZD'=>'Belize Dollar',
		'GYD'=>'Guyana Dollar',
		'JMD'=>'Jamaica Dollar',
		'TTD'=>'Trinidad and Tobago Dollar',
		'XCD'=>'Eastern Caribbean Dollar'
	);
	
	/*
	* @additional_targets: Add more currencies if available
	*/
	if( !empty( $additional_targets ) && is_array( $additional_targets ) ) {
		$target_currencies = array_merge( $default_targets, $additional_targets );
	} else {
		$target_currencies = $default_targets;
	}
	
	/*
	* @unset: Remove home currency from targets
	*/
	if( array_key_exists( $home_currency, $target_currencies ) ) {
		unset( $target_currencies[$home_currency] );
	}
	
	/*
	* @loop: Loop through the targets and perform lookup on Yahoo! Finance
	*/
	foreach( $target_currencies as $code => $name ) {
		/*
		* @url: Get the URL for csv file at Yahoo API, based on 'convert_to' option
		*/
		switch( strtoupper( $convert_to ) ) {
			case 'H': /* Converts targest to home */
				$url = sprintf( "http://finance.yahoo.com/d/quotes.csv?s=%s%s=X&f=sl1d1t1", $code, $home_currency );
			break;
			case 'T': /* Converts home to targets */
			default:
				$url = sprintf( "http://finance.yahoo.com/d/quotes.csv?s=%s%s=X&f=sl1d1t1", $home_currency, $code );
			break;
		}
		
		/*
		* @fopen: open and read API files
		*/
		$handle = @fopen( $url, 'r' );
		if ( $handle ) {
			$result = fgets( $handle, 4096 );
			fclose( $handle );
		}
		
		/*
		* @output: Create output array and add currency code and descriptive (Country) name
		*/
		$arrOutput[$code] = explode( ',', $result );
		array_unshift( $arrOutput[$code], $code ); /* Add the code */
		array_unshift( $arrOutput[$code], $name ); /* Add the name */
		
		/*
		* @keys: Substitute numerical keys with user friendly ones
		*/
		$arrOutput[$code] = add_cx_keys( $arrOutput[$code] );
	}
	
	/*
	* @object: Convert array to object if required
	*/
	if( strtoupper( $output_type ) == 'OBJECT' ) {
		$arrOutput = make_array_object( $arrOutput );
	}
	
	/*
	* @return: Return the output array or object
	*/
	return $arrOutput;
}

/*
* @function: make_array_object() | array_to_object() - convert an associative array to an object
*/
function make_array_object( $array ) {
	$object = new stdClass();
	return array_to_object( $array, $object );
}

function array_to_object( $arr, &$obj ) {
	foreach( $arr as $key=>$val )
	{
		if( is_array( $val ) )
		{
			$obj->$key = new stdClass();
			array_to_object( $val, $obj->$key );
		}
		else
		{
			$obj->$key = $val;
		}
	}
	return $obj;
}

/*
* @function: add_cx_keys( $array )
*/
function add_cx_keys( $array ) {
	$target_keys = array( 'cx_name', 'cx_code', 'cx_test', 'cx_rate', 'cx_date', 'cx_time' );
	$i = 0;
	foreach($target_keys as $key) {
		$arrOutput[$key] = $array[$i];
		$i++;
	}
	return $arrOutput;
}
?>

Open in new window

2
Comment
Author:Ovid Burke
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
Great article, and the Yahoo API looks like a good resource; I'm going to try it for my own work.

Here is a somewhat more complete set of currencies...
// DATA ADAPTED FROM XE.COM - SEE ALSO: http://en.wikipedia.org/wiki/ISO_4217
$this->currs["AED"] = array("N" => "United Arab Emirates",                                 "C" => "Dirhams");
$this->currs["AFN"] = array("N" => "Afghanistan",                                          "C" => "Afghanis");
$this->currs["ALL"] = array("N" => "Albania",                                              "C" => "Leke");
$this->currs["AMD"] = array("N" => "Armenia",                                              "C" => "Drams");
$this->currs["ANG"] = array("N" => "Netherlands Antilles",                                 "C" => "Guilders (also called Florins)");
$this->currs["AOA"] = array("N" => "Angola",                                               "C" => "Kwanza");
$this->currs["ARS"] = array("N" => "Argentina",                                            "C" => "Pesos");
$this->currs["AUD"] = array("N" => "Australia",                                            "C" => "Dollars");
$this->currs["AWG"] = array("N" => "Aruba",                                                "C" => "Guilders (also called Florins)");
$this->currs["AZN"] = array("N" => "Azerbaijan",                                           "C" => "New Manats");
$this->currs["BAM"] = array("N" => "Bosnia and Herzegovina",                               "C" => "Convertible Marka");
$this->currs["BBD"] = array("N" => "Barbados",                                             "C" => "Dollars");
$this->currs["BDT"] = array("N" => "Bangladesh",                                           "C" => "Taka");
$this->currs["BGN"] = array("N" => "Bulgaria",                                             "C" => "Leva");
$this->currs["BHD"] = array("N" => "Bahrain",                                              "C" => "Dinars");
$this->currs["BIF"] = array("N" => "Burundi",                                              "C" => "Francs");
$this->currs["BMD"] = array("N" => "Bermuda",                                              "C" => "Dollars");
$this->currs["BND"] = array("N" => "Brunei Darussalam",                                    "C" => "Dollars");
$this->currs["BOB"] = array("N" => "Bolivia",                                              "C" => "Bolivianos");
$this->currs["BRL"] = array("N" => "Brazil",                                               "C" => "Brazil Real");
$this->currs["BSD"] = array("N" => "Bahamas",                                              "C" => "Dollars");
$this->currs["BTN"] = array("N" => "Bhutan",                                               "C" => "Ngultrum");
$this->currs["BWP"] = array("N" => "Botswana",                                             "C" => "Pulas");
$this->currs["BYR"] = array("N" => "Belarus",                                              "C" => "Rubles");
$this->currs["BZD"] = array("N" => "Belize",                                               "C" => "Dollars");
$this->currs["CAD"] = array("N" => "Canada",                                               "C" => "Dollars");
$this->currs["CDF"] = array("N" => "Congo/Kinshasa",                                       "C" => "Congolese Francs");
$this->currs["CHF"] = array("N" => "Switzerland",                                          "C" => "Francs");
$this->currs["CLP"] = array("N" => "Chile",                                                "C" => "Pesos");
$this->currs["CNY"] = array("N" => "China",                                                "C" => "Yuan Renminbi");
$this->currs["COP"] = array("N" => "Colombia",                                             "C" => "Pesos");
$this->currs["CRC"] = array("N" => "Costa Rica",                                           "C" => "Colones");
$this->currs["CUP"] = array("N" => "Cuba",                                                 "C" => "Pesos");
$this->currs["CVE"] = array("N" => "Cape Verde",                                           "C" => "Escudos");
$this->currs["CYP"] = array("N" => "Cyprus",                                               "C" => "Pounds (expires 2008-Jan-31)");
$this->currs["CZK"] = array("N" => "Czech Republic",                                       "C" => "Koruny");
$this->currs["DJF"] = array("N" => "Djibouti",                                             "C" => "Francs");
$this->currs["DKK"] = array("N" => "Denmark",                                              "C" => "Kroner");
$this->currs["DOP"] = array("N" => "Dominican Republic",                                   "C" => "Pesos");
$this->currs["DZD"] = array("N" => "Algeria",                                              "C" => "Algeria Dinars");
$this->currs["EEK"] = array("N" => "Estonia",                                              "C" => "Krooni");
$this->currs["EGP"] = array("N" => "Egypt",                                                "C" => "Pounds");
$this->currs["ERN"] = array("N" => "Eritrea",                                              "C" => "Nakfa");
$this->currs["ETB"] = array("N" => "Ethiopia",                                             "C" => "Birr");
$this->currs["EUR"] = array("N" => "Euro Member Countries",                                "C" => "Euro");
$this->currs["FJD"] = array("N" => "Fiji",                                                 "C" => "Dollars");
$this->currs["FKP"] = array("N" => "Falkland Islands (Malvinas)",                          "C" => "Pounds");
$this->currs["GBP"] = array("N" => "United Kingdom",                                       "C" => "Pounds");
$this->currs["GEL"] = array("N" => "Georgia",                                              "C" => "Lari");
$this->currs["GGP"] = array("N" => "Guernsey",                                             "C" => "Pounds");
$this->currs["GHS"] = array("N" => "Ghana",                                                "C" => "Cedis");
$this->currs["GIP"] = array("N" => "Gibraltar",                                            "C" => "Pounds");
$this->currs["GMD"] = array("N" => "Gambia",                                               "C" => "Dalasi");
$this->currs["GNF"] = array("N" => "Guinea",                                               "C" => "Francs");
$this->currs["GTQ"] = array("N" => "Guatemala",                                            "C" => "Quetzales");
$this->currs["GYD"] = array("N" => "Guyana",                                               "C" => "Dollars");
$this->currs["HKD"] = array("N" => "Hong Kong",                                            "C" => "Dollars");
$this->currs["HNL"] = array("N" => "Honduras",                                             "C" => "Lempiras");
$this->currs["HRK"] = array("N" => "Croatia",                                              "C" => "Kuna");
$this->currs["HTG"] = array("N" => "Haiti",                                                "C" => "Gourdes");
$this->currs["HUF"] = array("N" => "Hungary",                                              "C" => "Forint");
$this->currs["IDR"] = array("N" => "Indonesia",                                            "C" => "Rupiahs");
$this->currs["ILS"] = array("N" => "Israel",                                               "C" => "New Shekels");
$this->currs["IMP"] = array("N" => "Isle of Man",                                          "C" => "Pounds");
$this->currs["INR"] = array("N" => "India",                                                "C" => "Rupees");
$this->currs["IQD"] = array("N" => "Iraq",                                                 "C" => "Dinars");
$this->currs["IRR"] = array("N" => "Iran",                                                 "C" => "Rials");
$this->currs["ISK"] = array("N" => "Iceland",                                              "C" => "Kronur");
$this->currs["JEP"] = array("N" => "Jersey",                                               "C" => "Pounds");
$this->currs["JMD"] = array("N" => "Jamaica",                                              "C" => "Dollars");
$this->currs["JOD"] = array("N" => "Jordan",                                               "C" => "Dinars");
$this->currs["JPY"] = array("N" => "Japan",                                                "C" => "Yen");
$this->currs["KES"] = array("N" => "Kenya",                                                "C" => "Shillings");
$this->currs["KGS"] = array("N" => "Kyrgyzstan",                                           "C" => "Soms");
$this->currs["KHR"] = array("N" => "Cambodia",                                             "C" => "Riels");
$this->currs["KMF"] = array("N" => "Comoros",                                              "C" => "Francs");
$this->currs["KPW"] = array("N" => "Korea (North)",                                        "C" => "Won");
$this->currs["KRW"] = array("N" => "Korea (South)",                                        "C" => "Won");
$this->currs["KWD"] = array("N" => "Kuwait",                                               "C" => "Dinars");
$this->currs["KYD"] = array("N" => "Cayman Islands",                                       "C" => "Dollars");
$this->currs["KZT"] = array("N" => "Kazakhstan",                                           "C" => "Tenge");
$this->currs["LAK"] = array("N" => "Laos",                                                 "C" => "Kips");
$this->currs["LBP"] = array("N" => "Lebanon",                                              "C" => "Pounds");
$this->currs["LKR"] = array("N" => "Sri Lanka",                                            "C" => "Rupees");
$this->currs["LRD"] = array("N" => "Liberia",                                              "C" => "Dollars");
$this->currs["LSL"] = array("N" => "Lesotho",                                              "C" => "Maloti");
$this->currs["LTL"] = array("N" => "Lithuania",                                            "C" => "Litai");
$this->currs["LVL"] = array("N" => "Latvia",                                               "C" => "Lati");
$this->currs["LYD"] = array("N" => "Libya",                                                "C" => "Dinars");
$this->currs["MAD"] = array("N" => "Morocco",                                              "C" => "Dirhams");
$this->currs["MDL"] = array("N" => "Moldova",                                              "C" => "Lei");
$this->currs["MGA"] = array("N" => "Madagascar",                                           "C" => "Ariary");
$this->currs["MKD"] = array("N" => "Macedonia",                                            "C" => "Denars");
$this->currs["MMK"] = array("N" => "Myanmar (Burma)",                                      "C" => "Kyats");
$this->currs["MNT"] = array("N" => "Mongolia",                                             "C" => "Tugriks");
$this->currs["MOP"] = array("N" => "Macau",                                                "C" => "Patacas");
$this->currs["MRO"] = array("N" => "Mauritania",                                           "C" => "Ouguiyas");
$this->currs["MTL"] = array("N" => "Malta",                                                "C" => "Liri (expires 2008-Jan-31)");
$this->currs["MUR"] = array("N" => "Mauritius",                                            "C" => "Rupees");
$this->currs["MVR"] = array("N" => "Maldives (Maldive Islands)",                           "C" => "Rufiyaa");
$this->currs["MWK"] = array("N" => "Malawi",                                               "C" => "Kwachas");
$this->currs["MXN"] = array("N" => "Mexico",                                               "C" => "Pesos");
$this->currs["MYR"] = array("N" => "Malaysia",                                             "C" => "Ringgits");
$this->currs["MZN"] = array("N" => "Mozambique",                                           "C" => "Meticais");
$this->currs["NAD"] = array("N" => "Namibia",                                              "C" => "Dollars");
$this->currs["NGN"] = array("N" => "Nigeria",                                              "C" => "Nairas");
$this->currs["NIO"] = array("N" => "Nicaragua",                                            "C" => "Cordobas");
$this->currs["NOK"] = array("N" => "Norway",                                               "C" => "Krone");
$this->currs["NPR"] = array("N" => "Nepal",                                                "C" => "Nepal Rupees");
$this->currs["NZD"] = array("N" => "New Zealand",                                          "C" => "Dollars");
$this->currs["OMR"] = array("N" => "Oman",                                                 "C" => "Rials");
$this->currs["PAB"] = array("N" => "Panama",                                               "C" => "Balboa");
$this->currs["PEN"] = array("N" => "Peru",                                                 "C" => "Nuevos Soles");
$this->currs["PGK"] = array("N" => "Papua New Guinea",                                     "C" => "Kina");
$this->currs["PHP"] = array("N" => "Philippines",                                          "C" => "Pesos");
$this->currs["PKR"] = array("N" => "Pakistan",                                             "C" => "Rupees");
$this->currs["PLN"] = array("N" => "Poland",                                               "C" => "Zlotych");
$this->currs["PYG"] = array("N" => "Paraguay",                                             "C" => "Guarani");
$this->currs["QAR"] = array("N" => "Qatar",                                                "C" => "Rials");
$this->currs["RON"] = array("N" => "Romania",                                              "C" => "New Lei");
$this->currs["RSD"] = array("N" => "Serbia",                                               "C" => "Dinars");
$this->currs["RUB"] = array("N" => "Russia",                                               "C" => "Rubles");
$this->currs["RWF"] = array("N" => "Rwanda",                                               "C" => "Rwanda Francs");
$this->currs["SAR"] = array("N" => "Saudi Arabia",                                         "C" => "Riyals");
$this->currs["SBD"] = array("N" => "Solomon Islands",                                      "C" => "Dollars");
$this->currs["SCR"] = array("N" => "Seychelles",                                           "C" => "Rupees");
$this->currs["SDG"] = array("N" => "Sudan",                                                "C" => "Pounds");
$this->currs["SEK"] = array("N" => "Sweden",                                               "C" => "Kronor");
$this->currs["SGD"] = array("N" => "Singapore",                                            "C" => "Dollars");
$this->currs["SHP"] = array("N" => "Saint Helena",                                         "C" => "Pounds");
$this->currs["SLL"] = array("N" => "Sierra Leone",                                         "C" => "Leones");
$this->currs["SOS"] = array("N" => "Somalia",                                              "C" => "Shillings");
$this->currs["SPL"] = array("N" => "Seborga",                                              "C" => "Luigini");
$this->currs["SRD"] = array("N" => "Suriname",                                             "C" => "Dollars");
$this->currs["STD"] = array("N" => "S&atilde;o Tome and Principe",                         "C" => "Dobras");
$this->currs["SVC"] = array("N" => "El Salvador",                                          "C" => "Colones");
$this->currs["SYP"] = array("N" => "Syria",                                                "C" => "Pounds");
$this->currs["SZL"] = array("N" => "Swaziland",                                            "C" => "Emalangeni");
$this->currs["THB"] = array("N" => "Thailand",                                             "C" => "Baht");
$this->currs["TJS"] = array("N" => "Tajikistan",                                           "C" => "Somoni");
$this->currs["TMM"] = array("N" => "Turkmenistan",                                         "C" => "Manats");
$this->currs["TND"] = array("N" => "Tunisia",                                              "C" => "Dinars");
$this->currs["TOP"] = array("N" => "Tonga",                                                "C" => "Pa&apos;anga");
$this->currs["TRY"] = array("N" => "Turkey",                                               "C" => "New Lira");
$this->currs["TTD"] = array("N" => "Trinidad and Tobago",                                  "C" => "Dollars");
$this->currs["TVD"] = array("N" => "Tuvalu",                                               "C" => "Tuvalu Dollars");
$this->currs["TWD"] = array("N" => "Taiwan",                                               "C" => "New Dollars");
$this->currs["TZS"] = array("N" => "Tanzania",                                             "C" => "Shillings");
$this->currs["UAH"] = array("N" => "Ukraine",                                              "C" => "Hryvnia");
$this->currs["UGX"] = array("N" => "Uganda",                                               "C" => "Shillings");
$this->currs["USD"] = array("N" => "United States of America",                             "C" => "Dollars");
$this->currs["UYU"] = array("N" => "Uruguay",                                              "C" => "Pesos");
$this->currs["UZS"] = array("N" => "Uzbekistan",                                           "C" => "Sums");
$this->currs["VEB"] = array("N" => "Venezuela",                                            "C" => "Bolivares (expires 2008-Jun-30)");
$this->currs["VEF"] = array("N" => "Venezuela",                                            "C" => "Bolivares Fuertes");
$this->currs["VND"] = array("N" => "Viet Nam",                                             "C" => "Dong");
$this->currs["VUV"] = array("N" => "Vanuatu",                                              "C" => "Vatu");
$this->currs["WST"] = array("N" => "Samoa",                                                "C" => "Tala");
$this->currs["XAF"] = array("N" => "Communaut&eacute; Financi&egrave;re Africaine BEAC",   "C" => "Francs");
$this->currs["XAG"] = array("N" => "Silver",                                               "C" => "Ounces");
$this->currs["XAU"] = array("N" => "Gold",                                                 "C" => "Ounces");
$this->currs["XCD"] = array("N" => "East Caribbean",                                       "C" => "Dollars");
$this->currs["XDR"] = array("N" => "IMF Special Drawing Rights",                           "C" => "XDR");
$this->currs["XOF"] = array("N" => "Communaut&eacute; Financi&egrave;re Africaine BCEAO",  "C" => "Francs");
$this->currs["XPD"] = array("N" => "Palladium",                                            "C" => "Ounces");
$this->currs["XPF"] = array("N" => "Comptoirs Fran&ccedil;ais du Pacifique Francs",        "C" => "CFP Francs");
$this->currs["XPT"] = array("N" => "Platinum",                                             "C" => "Ounces");
$this->currs["YER"] = array("N" => "Yemen",                                                "C" => "Rials");
$this->currs["ZAR"] = array("N" => "South Africa",                                         "C" => "Rand");
$this->currs["ZMK"] = array("N" => "Zambia",                                               "C" => "Kwacha");
$this->currs["ZWD"] = array("N" => "Zimbabwe",                                             "C" => "Zimbabwe Dollars");

Open in new window

0
 

Expert Comment

by:Harry Espino
Yahoo finance API is not available anymore. I have moved to MarketXLS after this change, much more reliable data.
0
 
LVL 11

Author Comment

by:Ovid Burke
I'll have to take at MarketXLS, and maybe do some refactoring then. Thanks for your comment.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Join & Write a Comment

Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month