Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
Dawg
RavenNuke(tm) Development Team



Joined: Nov 07, 2003
Posts: 928

PostPosted: Fri Apr 13, 2007 6:06 am Reply with quote

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
 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Sat Apr 14, 2007 2:06 pm Reply with quote

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.
 
View user's profile Send private message
montego
Site Admin



Joined: Aug 29, 2004
Posts: 9457
Location: Arizona

PostPosted: Sun Apr 15, 2007 1:45 pm Reply with quote

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! 
View user's profile Send private message Visit poster's website
Dawg







PostPosted: Mon Apr 16, 2007 4:31 am Reply with quote

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







PostPosted: Mon Apr 16, 2007 6:55 am Reply with quote

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.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©