Plik plik.xml zawiera treść jaką otrzymuję pod adresem: https://maps.googleapis.com/maps/api/distan...1382,-3.7914676 i wygląda tak:
W pliku PHP odczytuję zawartość pliku plik.xml:
<?xml version="1.0" encoding="UTF-8"?> <DistanceMatrixResponse> <status>OK</status> <origin_address>Two Stiles, Water Ln, Speen, Princes Risborough, Buckinghamshire HP27 0SW, Wielka Brytania</origin_address> <destination_address>27-29 Penywern Rd, Ystalyfera, Swansea, Neath Port Talbot SA9, Wielka Brytania</destination_address> <row> <element> <status>OK</status> <duration> <value>11540</value> <text>3 godz. 12 min</text> </duration> <distance> <value>296079</value> <text>296 km</text> </distance> </element> </row> </DistanceMatrixResponse>
W ten sposób działa dobrze, dostaję to, co potrzebuję.
<?php $reader = new XMLReader(); $reader->open('plik.xml'); //$reader->open('https://maps.googleapis.com/maps/api/distancematrix/xml?origins=51.6896118,-0.7846495&destinations=51.7651382,-3.7914676'); while($reader->read()) { if($reader->nodeType == XMLReader::ELEMENT) { $name = $reader->name; } if($reader->nodeType == XMLReader::TEXT) { } } $reader->close(); ?>
Jeżeli jednak zamiast
Ustawię:
$reader->open('plik.xml');
To otrzymuję pustą stronę.... W jaki sposób załadować XMLa jako wynik działania skryptu googla?
$reader->open('https://maps.googleapis.com/maps/api/distancematrix/xml?origins=51.6896118,-0.7846495&destinations=51.7651382,-3.7914676');
Pozdrawiam.