evert Posted September 2, 2007 Share Posted September 2, 2007 Hi all! I have a file containing: Amsterdam Airport Schiphol, Netherlands (EHAM) 52-18N 004-46E -2M Sep 02, 2007 - 04:55 PM EDT / 2007.09.02 2055 UTC Wind: from the W (260 degrees) at 12 MPH (10 KT):0 Visibility: 3 mile(s):0 Sky conditions: mostly cloudy Weather: light rain, drizzle Temperature: 62 F (17 C) Dew Point: 60 F (16 C) Relative Humidity: 93% Pressure (altimeter): 29.88 in. Hg (1012 hPa) ob: EHAM 022055Z 26010KT 5000 -RADZ FEW006 BKN020 BKN035 17/16 Q1012 TEMPO 4000 BKN012 cycle: 21 And I need to turn this into a single line containing: Humidity:93 FeelsLike:16 Wind:12 DewPoint:16.0 Temp:17.0 Rain:0.00 Pressure:1012 This exceeds my PHP skills... Who can help me out? Greetings, Evert Quote Link to comment https://forums.phpfreaks.com/topic/67691-how-do-i-turn-this-textfile-into-a-single-line/ Share on other sites More sharing options...
effigy Posted September 4, 2007 Share Posted September 4, 2007 Where does "FeelsLike" come from, and how is "Rain" associated to "0.00"? <pre> <?php $data = <<<DATA Amsterdam Airport Schiphol, Netherlands (EHAM) 52-18N 004-46E -2M Sep 02, 2007 - 04:55 PM EDT / 2007.09.02 2055 UTC Wind: from the W (260 degrees) at 12 MPH (10 KT):0 Visibility: 3 mile(s):0 Sky conditions: mostly cloudy Weather: light rain, drizzle Temperature: 62 F (17 C) Dew Point: 60 F (16 C) Relative Humidity: 93% Pressure (altimeter): 29.88 in. Hg (1012 hPa) ob: EHAM 022055Z 26010KT 5000 -RADZ FEW006 BKN020 BKN035 17/16 Q1012 TEMPO 4000 BKN012 cycle: 21 DATA; $pieces = array( 'Wind' => '^Wind.+?(\d+) MPH', 'Humidity' => '^Relative Humidity: (\d+)%', 'Dew Point' => '^Dew Point.+?\((\d+)', 'Temperature' => '^Temperature.+?\((\d+)', 'Pressure' => '^Pressure.+?\((\d+)', ); foreach ($pieces as $key => $value) { preg_match("/$value/sm", $data, $matches); $result[$key] = $matches[1]; } print_r($result); ?> </pre> Quote Link to comment https://forums.phpfreaks.com/topic/67691-how-do-i-turn-this-textfile-into-a-single-line/#findComment-341297 Share on other sites More sharing options...
evert Posted September 4, 2007 Author Share Posted September 4, 2007 Oops... Forgot to mention that... The feel-temperature is calculated (here's an example in Javascript): <!-- Begin function windChill(form) { wind=eval(form.wind.value); temp=eval(form.temp.value); chill=(0.0817*(3.71*(Math.pow(wind, 0.5))+ 5.81-0.25*wind)*(temp-91.4)+91.4); form.windchill.value = chill; } // End --> (this is the formula for fahrenheit & miles/hour) And about the precipitation: It turns out the US METAR files look a bit different: Austin, Austin-Bergstrom International Airport, TX, United States (KAUS) 30-11-40N 097-40-12W 172M Sep 04, 2007 - 12:53 PM EDT / 2007.09.04 1653 UTC Wind: from the E (090 degrees) at 3 MPH (3 KT):0 Visibility: 9 mile(s):0 Sky conditions: overcast Weather: light rain Precipitation last hour: 0.01 inches Temperature: 75.9 F (24.4 C) Dew Point: 72.0 F (22.2 C) Relative Humidity: 87% Pressure (altimeter): 30.04 in. Hg (1017 hPa) ob: KAUS 041653Z 09003KT 9SM -RA BKN009 OVC150 24/22 A3004 RMK AO2 RAB1555 SLP163 P0001 T02440222 cycle: 17 Regards, Evert Quote Link to comment https://forums.phpfreaks.com/topic/67691-how-do-i-turn-this-textfile-into-a-single-line/#findComment-341396 Share on other sites More sharing options...
effigy Posted September 4, 2007 Share Posted September 4, 2007 To capture the decimal points, change \d to [\d.]. Can you handle everything else? Quote Link to comment https://forums.phpfreaks.com/topic/67691-how-do-i-turn-this-textfile-into-a-single-line/#findComment-341436 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.