PHP currency converter with XML feed

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm having trouble to modify this code(currency converter, a combination of
javascript and php, which uses an XML feed from to get
up to date exchange rates) to work with Not
worked for me. Any help will be appreciated.

  $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(' ');

  $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
      } 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 =
    //Get From amount in Euros
    var amount_in_euros = parseFloat(amount/currencies[currFrom]);
    var currTo =
    //Convert to new currency
    var final_amount = parseFloat(amount_in_euros) *
    document.getElementById('result').value = final_amount;
    <td width="50%">Convert <input type="text" id="from" />
    <select name="currencyFrom" >
    <? echo $options; ?>
    <td width="50%">
    To <select name="currencyTo" >
        <? echo $options; ?>
        <input type="text" id="result" />
    <td colspan="2"><div align="center"><input type="button" value="Convert"
onclick="convert()" /></div></td>


Re: PHP currency converter with XML feed

El 21/02/2011 14:11, astral escribió/wrote:
Quoted text here. Click to load it

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.

-- - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web:
-- Mi web de humor satinado:

Re: PHP currency converter with XML feed

Quoted text here. Click to load it

no, absolutely. This is small enough code. What not work? After I replaced
feed with , and changed other strings as

  $xml = simplexml_load_file(' ');

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


Re: PHP currency converter with XML feed

On 21-02-11 14:11, astral wrote:
Quoted text here. Click to load it

That site you mentioned gave help....

And "help" is not a question... ;)


Re: PHP currency converter with XML feed

Quoted text here. Click to load it

Does someone know better currency convertrer php script to work with xml
feed, and without MySQL?

Re: PHP currency converter with XML feed

On 21-02-11 15:09, astral wrote:
Quoted text here. Click to load it


Site Timeline