[PHP] Very interesting and challenging question

2001-11-28 Thread Dan McCullough

I need to take a file, similar to this and strip it of everything but this, and write 
it to a
database.  Are there any thoughts on how to get the information out, all the files are 
consistent.
!-- start strip --
Race Final   Watkins Glen International
 2.450 miles31 laps

Fin Str  Driver Laps  Led   Pts Qual   Reason Out

!-- end strip --
!-- start output --
 1   2   18  Dynamike18   31   24   185  118.007  Running
 2   7   68  jcordeiro310   170  116.078  Running
 3   5   80  MattyJ140310   165  116.881  Running
 4   1   28  RUDD#28  316   165  118.219  Running
 5  13   57  1SpeedDemon  310   155   Running
 6   9   84  legends3 311   155  115.131  Running
 7   3   56  RobertFx3D   310   146  117.854  Running
 8  12   55  24skids  310   142   98.644  Running
 9   4   53  Mark_O_10310   138  117.323  Running
10   8   91  JJinsane 310   134  116.061  Running
11  108  beertipper   310   130  114.154  Running
12  11   44  WisOutLaw   100   127  111.022  DNF
13   6   51  BdgrOtlw  30   124  116.702  DNF
!-- End 1st output --

!-- Start second output --


Race time - 72:52.030

Average speed - 62.538mph

Margin of victory - 1.944sec

Caution flags - 7

# of lead changes - 3

Weather - Clear 70^ E 0mph
!-- End second output --

thanks for any help


=
Dan McCullough
---
Theres no such thing as a problem unless the servers are on fire!
h: 603.444.9808
w: McCullough Family
w: At Work

__
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Very interesting and challenging question

2001-11-28 Thread Conor McTernan



I had something like this to do a couple of months back, unfortunately, my
code was deleted by someone smart in my office. But i can pretty much
remember the algorithim behind it. 

What I done was read in my file into a buffer, then use the explode function,
i think, or something like it, basicially there is a function that allows you
to parse a string using a set number of char as the delimiters, e.g. first
item = first 10 chars etc, i think i was able to differentiate the number of
chars, e.g. 10 for the first item, maybe 15 for the second and so on. 

I then read them all into an arry. once in the array it's a piece of cake, I
know which item in the array corresponds to which field from the original
file, e.g. item 1 = row 1 col 1, item 2 = row 1 col 2, item 5 = row 2 col 1
(assuming there are 4 cols). 

At this point you can just loop through the array inserting the fields into
the database, or whatever you want to do.

I cant remember what happens when I had empty fields. I think I may have had
to fill in all blank fields for some reason.


I'm not sure if this makes any sense. But I hope it's been a help.

Conor


On Wed, Nov 28, 2001 at 09:01:26AM -0800, Dan McCullough wrote:
 I need to take a file, similar to this and strip it of everything but this, and 
write it to a
 database.  Are there any thoughts on how to get the information out, all the files 
are consistent.
 !-- start strip --
 Race Final   Watkins Glen International
  2.450 miles31 laps
 
 Fin Str  Driver Laps  Led   Pts Qual   Reason Out
 
 !-- end strip --
 !-- start output --
  1   2   18  Dynamike18   31   24   185  118.007  Running
  2   7   68  jcordeiro310   170  116.078  Running
  3   5   80  MattyJ140310   165  116.881  Running
  4   1   28  RUDD#28  316   165  118.219  Running
  5  13   57  1SpeedDemon  310   155   Running
  6   9   84  legends3 311   155  115.131  Running
  7   3   56  RobertFx3D   310   146  117.854  Running
  8  12   55  24skids  310   142   98.644  Running
  9   4   53  Mark_O_10310   138  117.323  Running
 10   8   91  JJinsane 310   134  116.061  Running
 11  108  beertipper   310   130  114.154  Running
 12  11   44  WisOutLaw   100   127  111.022  DNF
 13   6   51  BdgrOtlw  30   124  116.702  DNF
 !-- End 1st output --
 
 !-- Start second output --
 
 
 Race time - 72:52.030
 
 Average speed - 62.538mph
 
 Margin of victory - 1.944sec
 
 Caution flags - 7
 
 # of lead changes - 3
 
 Weather - Clear 70^ E 0mph
 !-- End second output --
 
 thanks for any help
 
 
 =
 Dan McCullough
 ---
 Theres no such thing as a problem unless the servers are on fire!
 h: 603.444.9808
 w: McCullough Family
 w: At Work
 
 __
 Do You Yahoo!?
 Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
 http://geocities.yahoo.com/ps/info1
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Very interesting and challenging question

2001-11-28 Thread Chris Bailey

You could read the file in with file(), which will give you each line as an
array.  Then, depending on how those strings are separated (are they by
tabs, or is it just whitespace?), use strtok() to tokenize each line.  If
they are by space, not tab, but you know the column width, then you can just
pull out each part by using substr() or similar.  For the non lap/time
records, just check whether the string starts with a number or not, and if
not check if it starts with the known labels, e.g. Caution Flags.

-Original Message-
From: Dan McCullough [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, November 28, 2001 9:01 AM
To: PHP General List
Subject: [PHP] Very interesting and challenging question


I need to take a file, similar to this and strip it of everything but this,
and write it to a
database.  Are there any thoughts on how to get the information out, all the
files are consistent.
!-- start strip --
Race Final   Watkins Glen International
 2.450 miles31 laps


Fin Str  Driver Laps  Led   Pts Qual   Reason
Out


!-- end strip --
!-- start output --
 1   2   18  Dynamike18   31   24   185  118.007
Running
 2   7   68  jcordeiro310   170  116.078
Running
 3   5   80  MattyJ140310   165  116.881
Running
 4   1   28  RUDD#28  316   165  118.219
Running
 5  13   57  1SpeedDemon  310   155
Running
 6   9   84  legends3 311   155  115.131
Running
 7   3   56  RobertFx3D   310   146  117.854
Running
 8  12   55  24skids  310   142   98.644
Running
 9   4   53  Mark_O_10310   138  117.323
Running
10   8   91  JJinsane 310   134  116.061
Running
11  108  beertipper   310   130  114.154
Running
12  11   44  WisOutLaw   100   127  111.022
DNF
13   6   51  BdgrOtlw  30   124  116.702
DNF
!-- End 1st output --

!-- Start second output --


Race time - 72:52.030

Average speed - 62.538mph

Margin of victory - 1.944sec

Caution flags - 7

# of lead changes - 3

Weather - Clear 70^ E 0mph
!-- End second output --

thanks for any help


=
Dan McCullough
---
Theres no such thing as a problem unless the servers are on fire!
h: 603.444.9808
w: McCullough Family
w: At Work

__
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Very interesting and challenging question

2001-11-28 Thread Chris Hobbs

A fellow wannabe Winston Cup driver :)
 
I'm thinking about setting a switch on $mode, which will change what it 
does based on the value of $mode. Something like this:

$mode = 1; // 1 for stripping text, 2 for adding driver results, 3 for 
adding race results
$file = file('/path/to/filename');
foreach ($file as $line) {
switch ($mode)  {
case 1: if (preg_match(/^ *[0-9][0-9]*  */, $line)) {
   $mode = 2;
   // split line up with explode() and enter it into db  
  }
break;
case 2: if (!preg_match(/^ *[0-9]* */, $line)) {
   $mode = 3;
} else {
// split line up with explode() and enter it into db
}
break;
case 3: if (preg_match(^[a-zA-Z#]*) { // avoid matching blank 
lines
// do whatever to put these into a INSERT query...
}
}
}

So in mode 1, it merely loops through lines until it finds one with zero 
or more spaces followed by one or more numbers followed by one or more 
spaces. When it hits one of those, it breaks that line apart and enters 
it into the db, then sets $mode to 2.

In mode 2, it continues to loop through looking for the same lines until 
it doesn't get a match, then sets mode 3.

Mode 3 looks for lines starting with text (skipping blank lines). It's 
left as an exercise for the reader to figure out how to get those values 
into the db :)

Hope this helps!

Chris Hobbs
#42 NNASCAR league :)


Dan McCullough wrote:

I need to take a file, similar to this and strip it of everything but this, and write 
it to a
database.  Are there any thoughts on how to get the information out, all the files 
are consistent.
!-- start strip --
Race Final   Watkins Glen International
 2.450 miles31 laps

Fin Str  Driver Laps  Led   Pts Qual   Reason Out

!-- end strip --
!-- start output --
 1   2   18  Dynamike18   31   24   185  118.007  Running
 2   7   68  jcordeiro310   170  116.078  Running
 3   5   80  MattyJ140310   165  116.881  Running
 4   1   28  RUDD#28  316   165  118.219  Running
 5  13   57  1SpeedDemon  310   155   Running
 6   9   84  legends3 311   155  115.131  Running
 7   3   56  RobertFx3D   310   146  117.854  Running
 8  12   55  24skids  310   142   98.644  Running
 9   4   53  Mark_O_10310   138  117.323  Running
10   8   91  JJinsane 310   134  116.061  Running
11  108  beertipper   310   130  114.154  Running
12  11   44  WisOutLaw   100   127  111.022  DNF
13   6   51  BdgrOtlw  30   124  116.702  DNF
!-- End 1st output --

!-- Start second output --


Race time - 72:52.030

Average speed - 62.538mph

Margin of victory - 1.944sec

Caution flags - 7

# of lead changes - 3

Weather - Clear 70^ E 0mph
!-- End second output --

thanks for any help


=
Dan McCullough
---
Theres no such thing as a problem unless the servers are on fire!
h: 603.444.9808
w: McCullough Family
w: At Work

__
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1

 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
   ___  ____    _
Chris Hobbs   / \ \/ / |  | |/ ___\|  __ \
Head Geek| (___  \ \  / /| |  | | (___ | |  | |
WebMaster \___ \  \ \/ / | |  | |\___ \| |  | |
PostMaster) |  \  /  | |__| |) | |__| |
  \/\/\/ \/|_/
  http://www.silvervalley.k12.ca.us
  [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]