TFD3 Posted August 20, 2007 Share Posted August 20, 2007 The script below runs this website: http://www.alabamaweather.org/beta/places/textversion/metar_text.php?icao=KBHM Open that page and you get a line of text which is what I want however I need the script below edited to let me add another METAR station to the end of the URL. The URL above as KBHM at the very end, thats one METAR station, now I would like to have it like: KBHM,KGLD,KTCL and so on and for every METAR station I add the output adds the info on a new line. Example: Current: http://www.alabamaweather.org/beta/places/textversion/metar_text.php?icao=KBHM When viewed you see: 33.5667,-86.75,1,89°F,KBHM-AL\nTemp: 89°F 31.7°C\nHeat Index: 92°F 33°C\nDewpoint: 67°F 19.4°C\nHumidity: 48.2%\nHumidity Index: 101.5°F 38.6°C\nWind: 270 @ 5.8 MPH\nPressure: 30.04" 1017mb\nVisibility: 9.0 Miles\nWx/Sky: /\nCloud Height: FT Now, what I would like it do is: http://www.alabamaweather.org/beta/places/textversion/metar_text.php?icao=KBHM,KTCL,ECT... Which would display the aditional data... 33.5667,-86.75,1,89°F,KBHM-AL\nTemp: 89°F 31.7°C\nHeat Index: 92°F 33°C\nDewpoint: 67°F 19.4°C\nHumidity: 48.2%\nHumidity Index: 101.5°F 38.6°C\nWind: 270 @ 5.8 MPH\nPressure: 30.04" 1017mb\nVisibility: 9.0 Miles\nWx/Sky: /\nCloud Height: FT 33.2167,-87.6167,1,89°F,KTCL-AL\nTemp: 89°F 31.7°C\nHeat Index: 94°F 34°C\nDewpoint: 69°F 20.6°C\nHumidity: 51.9%\nHumidity Index: 103.3°F 39.6°C\nWind: 190 @ 4.6 MPH\nPressure: 30.00" 1016mb\nVisibility: 10.0 Miles\nWx/Sky: /\nCloud Height: FT Here is the script: <?php header('Content-type: text/plain'); $authcode = ' AUTH CODE'; $fontdir = "/home/alabamaw/public_html/beta/places/font/"; error_reporting(0); $icao = isset($HTTP_GET_VARS["icao"]) ? $HTTP_GET_VARS["icao"] : "0"; if (!preg_match('/^\w\w\w\w$/',$icao)) { exit; } $buildit = 0; $txt = "$tmpdir/current-$icao.txt"; if (file_exists($txt)) { $mtime = filemtime($txt); // cache every 10 minutes $time = time()-30; if ($mtime < $time) { $buildit = 1; } } else { $buildit = 1; } if ($buildit) { ignore_user_abort(true); $text = BuildText(); print $text; } /////////////////////////////////////////////////// function BuildText() { global $icao,$authcode,$short_name; // Get URL of data based on state above $lines = file("http://places.allisonhouse.com/data/$authcode/raw/sfcobs/ascii.php?icaos=$icao"); foreach ($lines as $line) { if (!preg_match("/^;/",$line)) { $parsed = explode('#',$line); } } if (!isset($parsed)) { return ; } echo($parsed[2]); echo ","; echo($parsed[3]); echo ","; echo "1"; echo ","; list($temp_f,$temp_c) = explode('/',$parsed[13]); echo "$temp_f"; echo "°"; echo "F"; echo ","; echo($parsed[0]); echo "-"; echo($parsed[1]); echo "\\n"; echo "Temp:"; list($temp_f,$temp_c) = explode('/',$parsed[13]); echo " $temp_f"; echo "°F"; list($temp_f,$temp_c) = explode('/',$parsed[13]); echo " $temp_c"; echo "°C"; echo "\\n"; echo "Heat Index: "; list($hdx_f,$hdx_c) = explode('/',$parsed[18]); echo "$hdx_f"; echo "°F"; list($hdx_f,$hdx_c) = explode('/',$parsed[18]); echo " $hdx_c"; echo "°C"; echo "\\n"; echo "Dewpoint:"; list($dew_f,$dew_c) = explode('/',$parsed[14]); echo " $dew_f"; echo "°F"; list($dew_f,$dew_c) = explode('/',$parsed[14]); echo " $dew_c"; echo "°C"; echo "\\n"; echo "Humidity: "; echo($parsed[16]); echo "%"; echo "\\n"; echo "Humidity Index: "; list($HI_f,$HI_c) = explode('/',$parsed[19]); echo "$HI_f"; echo "°F"; list($HI_f,$HI_c) = explode('/',$parsed[19]); echo " $HI_c"; echo "°C"; echo "\\n"; echo "Wind: "; list($wind_dir,$wind_knots,$wind_mps,$wind_mph) = explode('/',$parsed[9]); echo "$wind_dir"; echo " @"; echo " $wind_mph"; echo " MPH\\n"; echo "Pressure:"; list($pressure,$b,$c,$d)=explode('/',$parsed[15]); echo " $pressure"; echo"\""; list($pressure,$b,$c,$d)=explode('/',$parsed[15]); echo " $c"; echo"mb"; echo "\\n"; echo "Visibility:"; list($visibility_miles,$visibility_ft,$visibility_km,$visibility_meter) = explode('/',$parsed[10]); echo " $visibility_miles"; echo " Miles"; echo "\\n"; echo "Wx/Sky: "; echo($parsed[11]); echo "\\n"; echo "Cloud Height: "; list($ceiling_ft,$ceiling_meter)=explode('/',$parsed[12]); echo "$ceiling_ft"; echo " FT"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65743-solved-adding-text-to-end-of-url/ Share on other sites More sharing options...
sasa Posted August 20, 2007 Share Posted August 20, 2007 try <?php header('Content-type: text/plain'); $authcode = ' AUTH CODE'; $fontdir = "/home/alabamaw/public_html/beta/places/font/"; error_reporting(0); $icao_array = isset($HTTP_GET_VARS["icao"]) ? explode(',',$HTTP_GET_VARS["icao"]) : array(); foreach($icao_array as $icao){ if (!preg_match('/^\w\w\w\w$/',$icao)) { exit; } $buildit = 0; $txt = "$tmpdir/current-$icao.txt"; if (file_exists($txt)) { $mtime = filemtime($txt); // cache every 10 minutes $time = time()-30; if ($mtime < $time) { $buildit = 1; } } else { $buildit = 1; } if ($buildit) { ignore_user_abort(true); $text = BuildText(); print $text; } } Quote Link to comment https://forums.phpfreaks.com/topic/65743-solved-adding-text-to-end-of-url/#findComment-328407 Share on other sites More sharing options...
TFD3 Posted August 20, 2007 Author Share Posted August 20, 2007 didnt work Parse error: syntax error, unexpected '=' in /home2/alabamaw/public_html/beta/places/textversion/metar_text.php on line 4 <?php header('Content-type: text/plain'); $authcode = 'code'; $fontdir = "/home/alabamaw/public_html/beta/places/font/"; error_reporting(0); $icao_array = isset($HTTP_GET_VARS["icao"]) ? explode(',',$HTTP_GET_VARS["icao"]) : array(); foreach($icao_array as $icao){ if (!preg_match('/^\w\w\w\w$/',$icao)) { exit; } $buildit = 0; $txt = "$tmpdir/current-$icao.txt"; if (file_exists($txt)) { $mtime = filemtime($txt); // cache every 10 minutes $time = time()-30; if ($mtime < $time) { $buildit = 1; } } else { $buildit = 1; } if ($buildit) { ignore_user_abort(true); $text = BuildText(); print $text; } } /////////////////////////////////////////////////// function BuildText() { global $icao,$authcode,$short_name; // Get URL of data based on state above $lines = file("http://places.allisonhouse.com/data/$authcode/raw/sfcobs/ascii.php?icaos=$icao"); foreach ($lines as $line) { if (!preg_match("/^;/",$line)) { $parsed = explode('#',$line); } } if (!isset($parsed)) { return ; } echo($parsed[2]); echo ","; echo($parsed[3]); echo ","; echo "1"; echo ","; list($temp_f,$temp_c) = explode('/',$parsed[13]); echo "$temp_f"; echo "°"; echo "F"; echo ","; echo($parsed[0]); echo "-"; echo($parsed[1]); echo "\\n"; echo "Temp:"; list($temp_f,$temp_c) = explode('/',$parsed[13]); echo " $temp_f"; echo "°F"; list($temp_f,$temp_c) = explode('/',$parsed[13]); echo " $temp_c"; echo "°C"; echo "\\n"; echo "Heat Index: "; list($hdx_f,$hdx_c) = explode('/',$parsed[18]); echo "$hdx_f"; echo "°F"; list($hdx_f,$hdx_c) = explode('/',$parsed[18]); echo " $hdx_c"; echo "°C"; echo "\\n"; echo "Dewpoint:"; list($dew_f,$dew_c) = explode('/',$parsed[14]); echo " $dew_f"; echo "°F"; list($dew_f,$dew_c) = explode('/',$parsed[14]); echo " $dew_c"; echo "°C"; echo "\\n"; echo "Humidity: "; echo($parsed[16]); echo "%"; echo "\\n"; echo "Humidity Index: "; list($HI_f,$HI_c) = explode('/',$parsed[19]); echo "$HI_f"; echo "°F"; list($HI_f,$HI_c) = explode('/',$parsed[19]); echo " $HI_c"; echo "°C"; echo "\\n"; echo "Wind: "; list($wind_dir,$wind_knots,$wind_mps,$wind_mph) = explode('/',$parsed[9]); echo "$wind_dir"; echo " @"; echo " $wind_mph"; echo " MPH\\n"; echo "Pressure:"; list($pressure,$b,$c,$d)=explode('/',$parsed[15]); echo " $pressure"; echo"\""; list($pressure,$b,$c,$d)=explode('/',$parsed[15]); echo " $c"; echo"mb"; echo "\\n"; echo "Visibility:"; list($visibility_miles,$visibility_ft,$visibility_km,$visibility_meter) = explode('/',$parsed[10]); echo " $visibility_miles"; echo " Miles"; echo "\\n"; echo "Wx/Sky: "; echo($parsed[11]); echo "\\n"; echo "Cloud Height: "; list($ceiling_ft,$ceiling_meter)=explode('/',$parsed[12]); echo "$ceiling_ft"; echo " FT"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/65743-solved-adding-text-to-end-of-url/#findComment-328415 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 erm.. you may wany to get that code again.. note the one you posted replaced the spaces with Quote Link to comment https://forums.phpfreaks.com/topic/65743-solved-adding-text-to-end-of-url/#findComment-328422 Share on other sites More sharing options...
TFD3 Posted August 20, 2007 Author Share Posted August 20, 2007 ok the script worked but its all showing up on one line. I would like to see if I can get them on seperate lines. Like 33.2167,-87.6167,1,84°F,KBHM-AL\nTemp: 84°F 28.9°C\nHeat Index: 90°F 33.2167,-87.6167,1,84°F,KTCL-AL\nTemp: 84°F 28.9°C\nHeat Index: 90°F 33.2167,-87.6167,1,84°F,KGLD-AL\nTemp: 84°F 28.9°C\nHeat Index: 90°F and so on... ?? Quote Link to comment https://forums.phpfreaks.com/topic/65743-solved-adding-text-to-end-of-url/#findComment-328428 Share on other sites More sharing options...
MadTechie Posted August 20, 2007 Share Posted August 20, 2007 what about echo "$ceiling_ft"; echo " FT"; to echo "$ceiling_ft"; echo " FT"; echo "<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/65743-solved-adding-text-to-end-of-url/#findComment-328445 Share on other sites More sharing options...
TFD3 Posted August 20, 2007 Author Share Posted August 20, 2007 what about echo "$ceiling_ft"; echo " FT"; to echo "$ceiling_ft"; echo " FT"; echo "<br>"; had to change < br > to \n and it worked! Thanks man!! Quote Link to comment https://forums.phpfreaks.com/topic/65743-solved-adding-text-to-end-of-url/#findComment-328450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.