PHP & XML - Fetching Property Properly?


#1

Hi, all…

In my efforts to make a page that takes two ICAO airport codes in from a database and outputs their weather information, I’ve come up with the following code:

<strong>Weather Information</strong>
<?php 

$depxml = simplexml_load_file("https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=" . $schedule->depicao . "&hoursBeforeNow=0.5") or die ("Error: Unable to read data");

$arrxml = simplexml_load_file("https://aviationweather.gov/adds/dataserver_current/httpparam?dataSource=metars&requestType=retrieve&format=xml&stationString=" . $schedule->arricao . "&hoursBeforeNow=0.5") or die ("Error: Unable to read data");
?>

<div id="<?php echo $schedule->depicao ?>" class="metar"><?php echo $schedule->depicao . ": " . $depxml->raw_text ?></div>
<div id="<?php echo $schedule->arricao ?>" class="metar"><?php echo $schedule->arricao . ": " . $arrxml->raw_text ?></div>

The result is the two codes with a colon, as expected, but with no data, like so:

EGLL:
KEWR:

I’ve also checked to make sure the data that I’m looking for exists, and it does at any given time. Insights? Many thanks. :airplane: