March 21st, 2003, 03:19 PM
Parsing METAR Data?
Anyone written a script/regular expression to parse out METAR data?
March 21st, 2003, 03:48 PM
I don't know if I speak for the rest of the board, but could you please be more descriptive as to what "METAR data" is?
March 21st, 2003, 03:57 PM
March 21st, 2003, 04:42 PM
That's cool, I didn't know there was a code for that sort of thing... Anyway, how are you getting the code? Is it being passed to you as a string, or is it stored in a text file or database? It really doesn't matter, but I didn't know if part of your question was [for example] pulling the info from a text file. If you can get the data into a string, you can to one of two things:
1) Use str_replace() to replace all line breaks with a pipe or some other character that your weather code doesn't use. Then explode() the data separated by a pipe (or whatever character you used) and then explode() those spaces.
2) Use REGEX to pull all the lines into an array (broken apart with a line break) and then explode() the spaces.
I hope this helps.
March 21st, 2003, 05:01 PM
Thanks. I think I have a good idea as to how to try to parse it now... explode on all the " ", Loop through the array, and do a lot of if statements to find the data I need.. store data in a strings.
Not pretty but should work none the less.
I will try tonight. post it here if I succeed.
March 21st, 2003, 05:21 PM
maybe you can improve performance and usability of the code using a class and instead of writing loads of "if"s, you can use the switch operator.
i don't know what kind of data is that, but i can give you a hand if you want.
Just my 2 cents
June 26th, 2003, 06:08 PM
An answer to your question
Yes, someone has already written this so you don't have to duplicate the effort. I haven't tried it out yet but I'm going to.
Check out PHP Weather here