I made a simple website to show actually currency rates from bank website, here is xml from I got these data: http://www.nbp.pl/kursy/xml/LastA.xml. I put this into a code like that:
$xml = simplexml_load_file('http://www.nbp.pl/kursy/xml/LastA.xml');
and get it to variables like that:
<?php
for($i=0; $i<35; $i++){
$rate = (string)$xml->pozycja[$i]->kurs_sredni;
$name = (string)$xml->pozycja[$i]->nazwa_waluty;
$code = (string)$xml->pozycja[$i]->kod_waluty;
(echo here)
It works. But if I'd like to get this data from this xml, for example from yesterday: http://api.nbp.pl/api/exchangerates/tables/a/2017-04-05?format=xml, and do the same I have only errors:
Warning: simplexml_load_file(): http://api.nbp.pl/api/exchangerates/tables/a/2017-04-05:1: parser error : Start tag expected, '<' not found in [PATH] on line 13
Line 13:
$xml = simplexml_load_file('http://api.nbp.pl/api/exchangerates/tables/a/2017-04-05');
And other errors:
Warning: simplexml_load_file(): [{"table":"A","no":"067/A/NBP/2017","effectiveDate":"2017-04-05","rates":[{"curr in [PATH] on line 13
Warning: simplexml_load_file(): ^ in [PATH] on line 13
Notice: Trying to get property of non-object in [PATH] on line 18
Line 18:
$rate = (string)$xml->Rate[$i]->Mid;
What is difference between these xml's? What am I doing wrong? Could You help me?