<html>
<head>
<title>Currency Converter</title>
</head>
<body>
<?php
/************************************************************************************************************************
Copyright © 2007-2009 Stephen Smith
email: hide@address.com
This file is part of CurrencyConvert.
CurrencyConvert is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
CurrencyConvert is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with CurrencyConvert; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*************************************************************************************************************************/
//*************************** EXAMPLE USAGE *********************************
// Instantiate a new CurrencyConvert object
require_once( 'CurrencyConvert.class.php' ) ;
$quote = new CurrencyConvert( 'Google' ) ;
// Get the currencies available
$currency_list = $quote->currencies() ;
// If the form has been submitted then display the result
if ( isset( $_POST['from'] ) and isset( $_POST['to'] ) and isset( $_POST['value'] ) )
{
// Obtain a quotation, using the required currency symbols
$quote->convert( $_POST['from'], $_POST['to'], $_POST['date'] ) or die( 'Exchange rate lookup failed' ) ;
$from_value = $_POST['value'] ;
$to_value = $quote->price( $from_value ) ;
echo '<p><strong>' . $from_value . ' ' . $quote->name( 'from' ) . ' = ' . $to_value . ' ' . $quote->name( 'to' ) . '</strong></p>' ;
}
//Display the table with the drop-down currency lists
echo '<FORM name="CurrencyConvert" action="' . $_SERVER['PHP_SELF'] . '" method="POST">
<p>From:</p>
<SELECT name="from" class="dropdown">' ;
// The following line is optional and has been added to show how you can set
// a default currency (in this case British Pounds) using its currency symbol
echo '<OPTION name="from" value="GBP">' . $currency_list['GBP'] . ' (GBP)'. '</OPTION>' ;
foreach ( $currency_list as $symbol => $name )
{
echo '<OPTION name="from" value="' . $symbol . '">' . $name . ' (' . $symbol . ')'. '</OPTION>' ;
}
echo '</SELECT>
<p>To:</p>
<SELECT name="to" class="dropdown">' ;
foreach ( $currency_list as $symbol => $name )
{
echo '<OPTION name="from" value="' . $symbol . '">' . $name . ' (' . $symbol . ')'. '</OPTION>' ;
}
echo '</SELECT>
<p>Value:</p>
<INPUT name="value" type="text" value="" size="6">
<p>Date (leave blank for NOW)<br />Note that this only works for the "Yahoo2" data source</p>
<INPUT name="date" type="text" value="" size="12"> eg 23-Nov-2008, or Unix timestamp
<br /><br />
<INPUT name="convert" value="Calculate" type="submit">
</FORM>' ;
//************************** END EXAMPLE USAGE ******************************
?>
</body>
</html>