Re: Very interesting and challenging question

From: Date: Wed, 28 Nov 2001 17:40:04 +0000
Subject: Re: Very interesting and challenging question
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-75907@lists.php.net to get a copy of this message
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 miles    31 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  jcordeiro                    31    0   170  116.078      Running
3   5   80  MattyJ140                    31    0   165  116.881      Running
4   1   28  RUDD#28                      31    6   165  118.219      Running
5  13   57  1SpeedDemon                  31    0   155               Running
6   9   84  legends3                     31    1   155  115.131      Running
7   3   56  RobertFx3D                   31    0   146  117.854      Running
8  12   55  24skids                      31    0   142   98.644      Running
9   4   53  Mark_O_10                    31    0   138  117.323      Running
10   8   91  JJinsane                     31    0   134  116.061      Running
11  10    8  beertipper                   31    0   130  114.154      Running
12  11   44  Wis>OutLaw                   10    0   127  111.022          DNF
13   6   51  BdgrOtlw                      3    0   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: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net
-- _______ ___ _ ____ _____ Chris Hobbs / ____\ \ / / | | |/ ___\| __ \ Head Geek | (___ \ \ / /| | | | (___ | | | | WebMaster \___ \ \ \/ / | | | |\___ \| | | | PostMaster ____) | \ / | |__| |____) | |__| | \____/ \/ \____/ \____/|_____/ http://www.silvervalley.k12.ca.us chobbs@silvervalley.k12.ca.us

« previous php.general (#75907) next »