[thelist] dancing through text

johnpeace webshot at members.evolt.org
Mon Mar 18 17:09:00 CST 2002


I have a problem that I think is going to come up again and again...

<background>
I got Flash MX. I've been working on a Flash interface to some textual
weather data that is available on the web here,
http://www.prh.noaa.gov/pr/hnl/Products/hiwinds.html When I strated askign
for help in a Flash IRC channel (#flashhelp on EfNet) these action script
genius guys told me that XML would be the best way to get the data into
Flash. So, I wrote a PHP script that:
opens the file
makes an array out of lines 30-38
uses substr() to count the characters to assign the right data (by line
positioning) to the right variable.
and print this all out as XML

You can see my script's output at
http://www.simmerhawaii.com/flash/weather_data.php

Now, my script makes the assumption that the lines I want will always have
hte same line number (30-38), while pounding on my app over the last few
days, I've discovered that such is not the case...I have seen the data come
back from teh server 'off' by one line...that is no good.
</background>

<problem I need to solve>
I think the earlier I can extract out the lines I want to parse for data,
the better off I'll be. But I can't really loop through each line to test if
it's one that I want unless I have the lines busted into arrays...so.

I think I can assume that my lines always are within a 10 line range...So,
I'll always get something like

<pre>18/2054  1021.0   69 55     40/ 15  26  PHMK    Molokai APT/Molokai, HI
18/1914           70        56/ 17  23  AR05    Kalaupapa, Molokai

Maui:
TIME UTC  SLP     TT Td    DIR/SPD GST  Site
18/2054  1021.6   69 55     40/ 17  25  PHOG    Kahului Apt/Maui, HI
18/2045  1020.5   72 55     50/ 15  25  PHJH    Kapalua-West Maui/Maui, HI
18/1853           63        30/ 24  33  AR06    Kahoolawe
18/2120                     30/ 19  34  MW63    Maalaea Bay   (MWT HI63)
18/2120                    230/ 11      MW68    Haleakala     (MWT HI68)

Lanai:
TIME UTC  SLP     TT Td    DIR/SPD GST  Site
18/2045  1017.8   70 63     20/ 25  30  PHNY    Lanai Airport/Lanai, HI
</pre>

Now...I only want the rows under 'Maui', and of those I only want the ones
that have data in them (not the header row)...those are the rows I need to
parse into the XML. How do I isolate just those rows? I tried it after I was
in the loop that went through each line as an array item and tested for the
substr variable that contains "PHOG" on line 1...I set an if that only
extracted variables and added them to the XML output string if that variable
was one of the 5 that are listed in my Maui items...that didnt' work.

I'm unsure how to proceed, but I kind of need to get this working more
reliably soon...one of the flash guys that helped me wants to use it as an
example in a talk he's giving at a flash conference next week.

The finished product can be seen here:
http://www.simmerhawaii.com/flash/index.php
</problem>

thanks,
john corry




More information about the thelist mailing list