ERuiz Posted November 1, 2007 Share Posted November 1, 2007 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. Link to comment https://forums.phpfreaks.com/topic/75607-solved-retrieve-taf-instead-of-metar/ Share on other sites More sharing options...
ERuiz Posted November 1, 2007 Author Share Posted November 1, 2007 *SLAPS HEAD*! Nevermind guys, I fixed it. Link to comment https://forums.phpfreaks.com/topic/75607-solved-retrieve-taf-instead-of-metar/#findComment-382562 Share on other sites More sharing options...
Crew-Portal Posted November 1, 2007 Share Posted November 1, 2007 Great to hear you fixed it! Luv to see that CEO's of VIRTUAL Airlines Besides me are using PHPfreaks! Link to comment https://forums.phpfreaks.com/topic/75607-solved-retrieve-taf-instead-of-metar/#findComment-382565 Share on other sites More sharing options...
ERuiz Posted November 1, 2007 Author Share Posted November 1, 2007 Well, I THOUGHT I had it fixed! I need help again guys... function get_taf($station) { $fileName = "ftp://tgftp.nws.noaa.gov/data/forecasts/taf/stations/$station.TXT"; $taf = ''; $fileData = @file($fileName); if ($fileData != false) { list($i, $date) = each($fileData); while (list($i, $line) = each($fileData)) { $taf .= ' ' . trim($line); } $taf = trim(str_replace(' ', ' ', $taf)); } return $taf; } How can I have this script return "NO DATA AVAILABLE" to $taf, if the file is not found on the server? Link to comment https://forums.phpfreaks.com/topic/75607-solved-retrieve-taf-instead-of-metar/#findComment-382568 Share on other sites More sharing options...
PHP_PhREEEk Posted November 1, 2007 Share Posted November 1, 2007 function get_taf($station) { $fileName = "ftp://tgftp.nws.noaa.gov/data/forecasts/taf/stations/$station.TXT"; $taf = ''; $fileData = @file($fileName); if ($fileData != false) { list($i, $date) = each($fileData); while (list($i, $line) = each($fileData)) { $taf .= ' ' . trim($line); } $taf = trim(str_replace(' ', ' ', $taf)); } else { return 'NO DATA AVAILABLE'; } return $taf; } might work... PhREEEk Link to comment https://forums.phpfreaks.com/topic/75607-solved-retrieve-taf-instead-of-metar/#findComment-382573 Share on other sites More sharing options...
ERuiz Posted November 1, 2007 Author Share Posted November 1, 2007 function get_taf($station) { $fileName = "ftp://tgftp.nws.noaa.gov/data/forecasts/taf/stations/$station.TXT"; $taf = ''; $fileData = @file($fileName); if ($fileData != false) { list($i, $date) = each($fileData); while (list($i, $line) = each($fileData)) { $taf .= ' ' . trim($line); } $taf = trim(str_replace(' ', ' ', $taf)); } else { return 'NO DATA AVAILABLE'; } return $taf; } might work... PhREEEk Worked perfectly, thanks! Link to comment https://forums.phpfreaks.com/topic/75607-solved-retrieve-taf-instead-of-metar/#findComment-382767 Share on other sites More sharing options...
amocco Posted June 8, 2010 Share Posted June 8, 2010 Hello , i am interested and i m search a script in php to import metar data from noaa in mysql thanks function get_taf($station) { $fileName = "ftp://tgftp.nws.noaa.gov/data/forecasts/taf/stations/$station.TXT"; $taf = ''; $fileData = @file($fileName); if ($fileData != false) { list($i, $date) = each($fileData); while (list($i, $line) = each($fileData)) { $taf .= ' ' . trim($line); } $taf = trim(str_replace(' ', ' ', $taf)); } else { return 'NO DATA AVAILABLE'; } return $taf; } might work... PhREEEk Worked perfectly, thanks! Link to comment https://forums.phpfreaks.com/topic/75607-solved-retrieve-taf-instead-of-metar/#findComment-1069318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.