{source}<?php

$waluty = array ("USD","EUR","GBP");

$xml_url = "https://www.sgb.pl/wp-content/uploads/exchanges/waluty.xml";


if (($response_xml_data = file_get_contents($xml_url))===false){
echo "Error fetching XML \n";
} else {
libxml_use_internal_errors(true);

$data = simplexml_load_string($response_xml_data);

if (!$data) {
echo "Błąd ładowania XML z SGB \n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
} else {

echo "<p>";
//var_dump($data->tableNo);
//print_r($data->currencyTable);
echo "Tabela nr: ";
echo $data->tableNo;
echo "  z dnia: ";
echo $data->tableDate;
echo "  na godzinę: ";
echo $data->tableHour;
echo "</p>";
//Budujemy tabelę

echo "<table cellpadding=3>";
echo "<thead>";
echo "<tr>";
echo "<th rowspan=2>Waluta</th>";
echo "<th colspan=2>Dewizy</th>";
echo "<th colspan=2>Pieniądz</th>";
echo "<th rowspan=2>Średni NBP</th>";
echo "</tr>";
echo "<tr>";

echo "<th>Kupno</th>";
echo "<th>Sprzedaż</th>";
echo "<th>Kupno</th>";
echo "<th>Sprzedaż</th>";
echo "</tr>";

echo "</thead>";
echo "<tbody>";
foreach($data->exchangeRates->currency as $currency) {
 if (in_array($currency['name'], $waluty))
{

echo "<tr>";
echo "<td align=center>";
echo $currency['name'];
echo "</td>";
echo "<td align=right>";
echo $currency['buy'];
echo "</td>";
echo "<td align=right>";
echo $currency['sell'];
echo "</td>";
echo "<td align=right>";
echo $currency['money_buy'];
echo "</td>";
echo "<td align=right>";
echo $currency['money_sell'];
echo "</td>";
echo "<td align=right>";
echo $currency['average'];
echo "</td>";
echo "</tr>";
}
//tu koniec rzędu
}
// tu koniec tabeli
echo "</tbody>";
echo "</table>";
}
}
 


?>
{/source}