<?php
$real_currency_names = array();
$real_currency_names['EUR'] = "Euro";
$real_currency_names['USD'] = "US Dollar";
$real_currency_names['JPY'] = "Japanese Yen";
$real_currency_names['BGN'] = "Bulgarian Leva";
$real_currency_names['CZK'] = "Czech Koruny";
$real_currency_names['DKK'] = "Denmark Kroner";
$real_currency_names['EEK'] = "Estonia Krooni";
$real_currency_names['GBP'] = "British Pound";
$real_currency_names['HUF'] = "Hungary, Forint";
$real_currency_names['LTL'] = "Lithuania, Litai";
$real_currency_names['LVL'] = "Latvia, Lati";
$real_currency_names['PLN'] = "Poland, Zlotych";
$real_currency_names['RON'] = "Romania, New Lei";
$real_currency_names['SEK'] = "Sweden, Kronor";
$real_currency_names['CHF'] = "Switzerland, Francs";
$real_currency_names['NOK'] = "Norway, Krone";
$real_currency_names['HRK'] = "Croatia, Kuna";
$real_currency_names['RUB'] = "Russia, Rubles";
$real_currency_names['TRY'] = "Turkey, New Lira";
$real_currency_names['AUD'] = "Australia, Dollars";
$real_currency_names['BRL'] = "Brazil, Brazil Real";
$real_currency_names['CAD'] = "Canada, Dollars";
$real_currency_names['CNY'] = "China, Yuan Renminbi";
$real_currency_names['HKD'] = "Hong Kong, Dollars";
$real_currency_names['IDR'] = "Indonesia, Rupiahs";
$real_currency_names['INR'] = "India, Rupees";
$real_currency_names['KRW'] = "Korea (South), Won";
$real_currency_names['MXN'] = "Mexico, Pesos";
$real_currency_names['MYR'] = "Malaysia, Ringgits";
$real_currency_names['NZD'] = "New Zealand, Dollars";
$real_currency_names['PHP'] = "Philippines, Pesos";
$real_currency_names['SGD'] = "Singapore, Dollars";
$real_currency_names['THB'] = "Thailand, Baht";
$real_currency_names['ZAR'] = "South Africa, Rand";
$xml =
simplexml_load_file('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
$xmlString = $xml->asXML();
$pos = stripos($xmlString,"<cube currency=");
$xmlString = substr($xmlString,$pos);
$pos2 = stripos($xmlString,"</cube>");
$xmlString = substr($xmlString,0,$pos2);
$arr = explode("<Cube ",$xmlString);
$js_init = 'currencies["EUR"]=parseFloat(1);';
$options = '<option value="EUR">EUR</option>';
foreach ($arr as $value)
{
if (!empty($value))
{
$currency = substr($value,strlen('currency="'),3);
$curr_value = substr($value,intval(strlen('currency="')+ 11));
$curr_value = floatval($curr_value);
$js_init.= "currencies[\"$currency\"]=parseFloat($curr_value);";
$options.= "<option
value=\"$currency\">".$real_currency_names[$currency]."</option>";
} else {
//Do nothing
}
}
?>
<script type="text/javascript" language="javascript">
var currencies = new Array();
<? echo $js_init; ?>
function convert()
{
var amount = parseFloat(document.getElementById('from').value);
var currFrom =
document.getElementById('currencyFrom').options[document.getElementById('currencyFrom').options.selectedIndex].value;
//Get From amount in Euros
var amount_in_euros = parseFloat(amount/currencies[currFrom]);
var currTo =
document.getElementById('currencyTo').options[document.getElementById('currencyTo').options.selectedIndex].value;
//Convert to new currency
var final_amount = parseFloat(amount_in_euros) *
parseFloat(currencies[currTo]);
document.getElementById('result').value = final_amount;
}
</script>
<table>
<tr>
<td width="50%">Convert <input type="text" id="from" />
<select name="currencyFrom" >
<? echo $options; ?>
</select>
</td>
<td width="50%">
To <select name="currencyTo" >
<? echo $options; ?>
</select>
<input type="text" id="result" />
</td>
</tr>
<tr>
<td colspan="2"><div align="center"><input type="button" value="Convert"
onclick="convert()" /></div></td>
</tr>
</table>
Regards,
astral
Just a personal thought... You drop a couple hundred lines of code and
don't even bother explaining what is failing... It looks like you are
not looking for help or advise but for someone who'll do the job for you
for free.
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
no, absolutely. This is small enough code. What not work? After I replaced
feed with http://www.bank.lv/vk/xml.xml , and changed other strings as
follows:
$xml = simplexml_load_file('http://www.bank.lv/vk/xml.xml');
$xmlString = $xml->asXML();
$pos = stripos($xmlString,"<Currency=");
$xmlString = substr($xmlString,$pos);
$pos2 = stripos($xmlString,"</CRates>");
$xmlString = substr($xmlString,0,$pos2);
$arr = explode("<CRates ",$xmlString);
saved as html page when tested it - show just form with drop down selectors
with no values inside, and "convert" action not work also.
Thanks.
That site you mentioned gave help....
http://www.ecb.int/stats/exchange/eurofxref/html/index.en.html#dev
And "help" is not a question... ;)
--
Luuk
Does someone know better currency convertrer php script to work with xml
feed, and without MySQL?