This code retrieves information from another site:
<?php
$location = $ident;
get_taf($location);
function get_taf($location) {
$fileName = "ftp://tgftp.nws.noaa.gov/data/forecasts/taf/stations/$location.TXT";
$taf = '';
$fileData = @file($fileName);
if ($fileData != false) {
list($i, $date) = each($fileData);
$utc = strtotime(trim($date));
$time = date("D, jS M Y Hi",$utc);
while (list($i, $line) = each($fileData)) {
$taf .= ' ' . trim($line);
}
$taf = trim(str_replace(' ', ' ', $taf));
}
if(!empty($taf)){
echo "Issued: $time Z
<br><br>
$taf";
} else {
echo 'TAF not available';
}
}
?>
What its suppose to look like:
TAF KLBX 160541Z 1606/1706 15009KT P6SM FEW009 BKN013 OVC030
FM160900 15005KT P6SM SCT010 BKN035
FM161600 16010KT P6SM VCSH SCT012 BKN030
FM161900 18012KT P6SM SCT025 BKN040
FM170000 16005KT P6SM SCT012 BKN022
What it ends up looking like:
TAF KLBX 160541Z 1606/1706 15009KT P6SM FEW009 BKN013 OVC030 FM160900 15005KT P6SM SCT010 BKN035 FM161600 16010KT P6SM VCSH SCT012 BKN030 FM161900 18012KT P6SM SCT025 BKN040 FM170000 16005KT P6SM SCT012 BKN022
How do I maintain the spacing with the rows???
It is putting all the info on 1 line and it looks like a paragraoh instead a list.
Thanks
preg_replace('/(FM)/', '<br />FM', $taf)
. If the file already contains the newlines you can usenl2br($taf)
to convert\n
(newline in text files) to<br>
. – dbrumann