Hello guys and gals,
I have a small problem. The following script:
<?php
function get_metar($station)
{
$fileName = "ftp://tgftp.nws.noaa.gov/data/observations/metar/stations/$station.TXT";
$metar = '';
$fileData = @file($fileName); // or die('Data not available');
if ($fileData != false)
{
list($i, $date) = each($fileData);
while (list($i, $line) = each($fileData))
{
$metar .= ' ' . trim($line);
}
$metar = trim(str_replace(' ', ' ', $metar));
}
return $metar;
}
$dep_station = "KMIA";
$dep_metar = get_metar($dep_station);
echo $dep_metar;
?>
fetches the file and displays it. The file's contents is this format:
2007/11/01 04:56
TJSJ 010456Z 10007KT 10SM FEW080 26/23 A2991 RMK AO2 SLP126 T02610228
Now, how can I change the code above, so that it will fetch a different file, which has the data stored in a different format such as this one:
2007/11/01 02:25
TAF
AMD KMIA 010225Z 010224 05009G20KT P6SM VCSH FEW015 SCT025 BKN045
FM0300 05011KT P6SM VCSH FEW015 SCT025 BKN045
FM1400 03016G26KT P6SM VCSH FEW015 SCT025 BKN040
FM1800 01014G24KT P6SM VCSH FEW015 SCT025 BKN040
I changed the URL on the code to point to the new data, but it will not display anything. Here is the code that needs to be fixed:
<?php
function get_metar($station)
{
$fileName = "ftp://tgftp.nws.noaa.gov/data/observations/taf/stations/$station.TXT";
$metar = '';
$fileData = @file($fileName); // or die('Data not available');
if ($fileData != false)
{
list($i, $date) = each($fileData);
while (list($i, $line) = each($fileData))
{
$metar .= ' ' . trim($line);
}
$metar = trim(str_replace(' ', ' ', $metar));
}
return $metar;
}
$dep_station = "KMIA";
$dep_metar = get_metar($dep_station);
echo $dep_metar;
?>
I might be wrong, but I think the code is not properly stripping down the data.