FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » PHP currency converter with XML feed
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
PHP currency converter with XML feed [message #172506] Mon, 21 February 2011 13:11 Go to next message
astral is currently offline  astral
Messages: 14
Registered: February 2011
Karma: 0
Junior Member
I'm having trouble to modify this code(currency converter, a combination of
javascript and php, which uses an XML feed from http://www.ecb.int/ to get
up to date exchange rates) to work with http://www.bank.lv/vk/xml.xml Not
worked for me. Any help will be appreciated.

<?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('cu rrencyFrom').options.selectedIndex].value;
//Get From amount in Euros
var amount_in_euros = parseFloat(amount/currencies[currFrom]);
var currTo =
document.getElementById('currencyTo').options[document.getElementById('curr encyTo').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
Re: PHP currency converter with XML feed [message #172507 is a reply to message #172506] Mon, 21 February 2011 13:25 Go to previous messageGo to next message
alvaro.NOSPAMTHANX is currently offline  alvaro.NOSPAMTHANX
Messages: 277
Registered: September 2010
Karma: 0
Senior Member
El 21/02/2011 14:11, astral escribió/wrote:
> I'm having trouble to modify this code(currency converter, a combination
> of javascript and php, which uses an XML feed from http://www.ecb.int/
> to get up to date exchange rates) to work with
> http://www.bank.lv/vk/xml.xml Not worked for me. Any help will be
> appreciated.

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
--
Re: PHP currency converter with XML feed [message #172509 is a reply to message #172507] Mon, 21 February 2011 13:47 Go to previous messageGo to next message
astral is currently offline  astral
Messages: 14
Registered: February 2011
Karma: 0
Junior Member
""Álvaro G. Vicario"" <alvaro(dot)NOSPAMTHANX(at)demogracia(dot)com(dot)invalid> wrote in
message news:ijtp4q$kkc$1(at)news(dot)eternal-september(dot)org...
> El 21/02/2011 14:11, astral escribió/wrote:
>> I'm having trouble to modify this code(currency converter, a combination
>> of javascript and php, which uses an XML feed from http://www.ecb.int/
>> to get up to date exchange rates) to work with
>> http://www.bank.lv/vk/xml.xml Not worked for me. Any help will be
>> appreciated.
>
> 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.
Re: PHP currency converter with XML feed [message #172510 is a reply to message #172506] Mon, 21 February 2011 13:49 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 21-02-11 14:11, astral wrote:
> I'm having trouble to modify this code(currency converter, a combination
> of javascript and php, which uses an XML feed from http://www.ecb.int/
> to get up to date exchange rates) to work with
> http://www.bank.lv/vk/xml.xml Not worked for me. Any help will be
> appreciated.
>
> .....
> Regards,
> astral

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
Re: PHP currency converter with XML feed [message #172514 is a reply to message #172510] Mon, 21 February 2011 14:09 Go to previous messageGo to next message
astral is currently offline  astral
Messages: 14
Registered: February 2011
Karma: 0
Junior Member
"Luuk" <Luuk(at)invalid(dot)lan> wrote in message
news:m37a38-nam(dot)ln1(at)luuk(dot)invalid(dot)lan...
> On 21-02-11 14:11, astral wrote:
>> I'm having trouble to modify this code(currency converter, a combination
>> of javascript and php, which uses an XML feed from http://www.ecb.int/
>> to get up to date exchange rates) to work with
>> http://www.bank.lv/vk/xml.xml Not worked for me. Any help will be
>> appreciated.
>>
>> .....
>> Regards,
>> astral
>
> 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?
Re: PHP currency converter with XML feed [message #172516 is a reply to message #172514] Mon, 21 February 2011 14:17 Go to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 21-02-11 15:09, astral wrote:
>
> "Luuk" <Luuk(at)invalid(dot)lan> wrote in message
> news:m37a38-nam(dot)ln1(at)luuk(dot)invalid(dot)lan...
>> On 21-02-11 14:11, astral wrote:
>>> I'm having trouble to modify this code(currency converter, a combination
>>> of javascript and php, which uses an XML feed from http://www.ecb.int/
>>> to get up to date exchange rates) to work with
>>> http://www.bank.lv/vk/xml.xml Not worked for me. Any help will be
>>> appreciated.
>>>
>>> .....
>>> Regards,
>>> astral
>>
>> 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?
>

http://lmgtfy.com/?q=%2Bcurrency+%2Bconverter+%2Bphp+%2Bscript+-mysql

--
Luuk
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Code Stops Working
Next Topic: about memory usage with application written with php and mysql
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Tue Nov 26 06:11:22 GMT 2024

Total time taken to generate the page: 0.02368 seconds