I am trying to adopt an online script which is very old, most of the bugs I have been able to fix but the last one eldues me.
I create a simple array with 3 elements and call the elements in the next line but get an error “undefined index”:
this is the line that generates the error:
foreach (array('EUR','GBP','USD') as $from) {
Reference rates European Central Bank
Conversion to Euros, Pounds, US Dollars from other currencies
**Notice** : Undefined index: GBP in **D:\xampp\htdocs\login-system\cart\currency-conversion.php** on line **69**
**Notice** : Undefined index: USD in **D:\xampp\htdocs\login-system\cart\currency-conversion.php** on line **69**
||Euros|Pounds|Dollars|
| --- | --- | --- | --- |
|1000 European Euro is about|1000.00|0.00|0.00|
> <?php
>
> $now = time();
> $cache = "$_SERVER[DOCUMENT_ROOT]/../include/erates.xml";
> $exchrate['EUR'] = 1.00;
> $amount = 1000;
>
> # Exchange rates - Grab current rates from European Central Bank
>
>
> $stuff = file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
>
> # Currency names that we'll use later on
>
> $names = array ('USD' => "US Dollar",
> 'JPY' => "Japanese Yen",
> 'DKK' => "Danish Krone",
> 'GBP' => "Pound Sterling",
> 'SEK' => "Swedish Krona",
> 'CHF' => "Swiss Franc",
> 'ISK' => "Icelandic Krona",
> 'NOK' => "Norwegian Krone",
> 'BGN' => "Bulgarian Lev",
> 'CYP' => "Cyprus Pound",
> 'CZK' => "Czech Koruna",
> 'EEK' => "Estonian Kroon",
> 'HUF' => "Hungarian Forint",
> 'LTL' => "Lithuanian Litas",
> 'LVL' => "Latvian Lats",
> 'MTL' => "Maltese Lira",
> 'PLN' => "Polish Zloty",
> 'ROL' => "Romanian Leu",
> 'SIT' => "Slovenian Tolar",
> 'SKK' => "Slovakian Koruna",
> 'TRY' => "New Turkish Lira 2005",
> 'AUD' => "Australian Dollar",
> 'CAD' => "Canadian Dollar",
> 'HKD' => "Hong Kong Dollar",
> 'NZD' => "New Zealand Dollar",
> 'SGD' => "Singapore Dollar",
> 'KRW' => "South Korean Won",
> 'EUR' => "European Euro",
> 'ZAR' => "South African Rand");
>
> # Extract data from page - conversion rates between each currency and the Euro
>
> foreach ($stuff as $line) {
>
> print_r($line);
> /* preg_match("currency='([[:alpha:]]+)'",$line,$gota);
> if (preg_match("rate='([[:graph:]]+)'",$line,$gotb)) {
> $exchrate[$gota[1]] = $gotb[1];
> } */
> }
>
> # Sample output - a table showing an amount converted to Euros,
> # Pounds and Dollars
>
> echo "<br>";
> print ("<b>Conversion to Euros, Pounds, US Dollars from other currencies</b><br>");
> echo "<br>";
> print ("<table cellpadding=5><tr><td> </td><th>Euros</th><th>Pounds</th><th>Dollars</th></tr>");
> foreach (array_keys($exchrate) as $to) {
> if ($names[$to] == "") $names[$to] = $to;
> print ("<tr><td>$amount $names[$to] is about </td>");
>
> foreach (array('EUR','GBP','USD') as $from) {
> $convertsto = sprintf("%.2f",$amount * $exchrate[$from] / $exchrate[$to]);
> print ("<td align=right>$convertsto</td>");
> }
> print ("</tr>");
> }
> print ("</table>");
> ?>