Author |
Message |
Dawg
RavenNuke(tm) Development Team

Joined: Nov 07, 2003
Posts: 928
|
Posted:
Fri Apr 13, 2007 6:06 am |
|
Greetings All,
I have some scripts that parse out NWS text files. They added another line to the head of these text files and I need to kill that line.
Old head
#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE
Now they are using this....
#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE
#yr mo dy hr mn degT m/s m/s m sec sec degT hPa degC degC degC mi hPa ft
More or less I need to KILL the second line in the code.
I have isolated the code that does this....
Code:
while((!feof($fpread)) && ($numLines < $maxReadings)) {
$line = eregi_replace("MM","N/A",$line);
list($YYYY,$MM,$DD,$HH,$SS,$WD,$WSPD,$GST,$WVHT,$DPD,$APD,$MWD,$BARO,$ATMP,$WTMP,$DEWP,$VIS,$PTDY,$TIDE,$WOOF) = preg_split("/[\s,]+/", $line);
|
I searched php ignore.....I bet it is simple....WITH the search term.
Dawg |
|
|
|
 |
Raven
Site Admin/Owner

Joined: Aug 27, 2002
Posts: 17088
|
Posted:
Sat Apr 14, 2007 2:06 pm |
|
What do you mean "KILL" that line?
$line = eregi_replace("MM","N/A",$line);
will change this line:
#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE
into
#YY N/A DD hh N/A WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE
I'm not seeing the correlation from the code and what you need. |
|
|
|
 |
montego
Site Admin

Joined: Aug 29, 2004
Posts: 9457
Location: Arizona
|
Posted:
Sun Apr 15, 2007 1:45 pm |
|
You could set a counter up front such as $counter = 0, then increment the counter right after a successful read of a new line of the file. Then, check for $counter == 2 and then if it is, just issue a continue. |
_________________ Only registered users can see links on this board! Get registered or login!
Only registered users can see links on this board! Get registered or login! |
|
|
 |
Dawg

|
Posted:
Mon Apr 16, 2007 4:31 am |
|
Sorry Guys I was off fishing all weekend.
This script parses Text from a data file.
It used to be like this at the top of the text file....
#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE
Now they are using this....
#YY MM DD hh mm WDIR WSPD GST WVHT DPD APD MWD PRES ATMP WTMP DEWP VIS PTDY TIDE
#yr mo dy hr mn degT m/s m/s m sec sec degT hPa degC degC degC mi hPa ft
More or less we need to KILL the first two lines in the text file they both start with #.
I have isolated the code that does the parseing....
while((!feof($fpread)) && ($numLines < $maxReadings)) {
$line = eregi_replace("MM","N/A",$line);
list($YYYY,$MM,$DD,$HH,$SS,$WD,$WSPD,$GST,$WVHT,$DPD,$APD,$MWD,$BARO,$ATMP,$WTMP,$DEWP,$VIS,$PTDY,$TIDE,$WOOF) = preg_split("/[\s,]+/", $line);
Link to the download of the existing file....
http://www.surfimplement.com/phpBuoy/phpBuoy_1.0.3.zip
It will not let me post more of the file here becasue of security. Try it using 41037 as the bouy and see what you get. Then it will make sence.
Out of everything I do in PHP the one thing I cannot seem to get my head wrapped around is parseing text.
Thanks for the help!
Dawg |
|
|
|
 |
montego

|
Posted:
Mon Apr 16, 2007 6:55 am |
|
It looks to me like "#" is used as a comment line. So, really, I think this is might not be too bad. However, based on the posted code so far, I guess I was assuming that you are reading the file one line at a time.
Without seeing the whole while loop code, I am a bit at a loss for what exactly to place where, but you somehow want to just skip any line which starts with "#". The following if statement might help you do this:
if (ereg('^#.*$', $line) {
skip the line
} else {
continue on with your processing code...
}
I cannot recall if "#" has special meaning in regex, so if this does not work, try '^\#' instead. |
|
|
|
 |
|