I'm trying to work on a website for a sports league, which inputs stats from Madden NFL 2008. I've looked up as much information as I can about parsing TXT files, but I'm still confused as to how to approach this. Specifically, I want to read the data from each section (general info, game settings, scoring info, game stats, home passing stats, home rushing stats, etc.), and enter them into separate tables.

I'll append an example to the end of this post.

If anyone can point me in the right direction, I'd be very grateful.

Madden NFL 08 PC v 3.0 Game Log - Lions at Bears
Game Time: Wed Oct 03 10:41:58 2007
Skill Level: All Pro
Quarter Length: 12 minute(s)

Slider                         Human   CPU
QB Accuracy                       56    56
Pass Blocking                     20    20
Receiver Catching                 70    70
Running Ability                   62    62
Offensive line Run Blocking       57    57
Defensive Awareness               50    50
Defensive line Knockdowns         20    20
Interceptions                      3     3
Defensive Break Blocks            15    15
Tackling                          50    50
Fieldgoal Length                  40    40
Fieldgoal Accuracy                99    99
Punt Length                       56    56
Punt Accuracy                     92    92
Kickoff Length                    57    57

Weather
Forecast: Fair
Wind: 4 mph
Temp: 74 degrees

Team               Q1   Q2   Q3   Q4   OT      FINAL
Lions               3    3    0    0    0          6
Bears               7    3    0    0    0         10

Game was not completed.

Game Statistics:                    Lions      Bears
First Downs                             8          6
Third Down Conversions                  1          3
Third Downs                             5          4
Third Down Percentage               20.0%      75.0%
Fourth Down Conversions                 0          0
Fourth Downs                            0          0
Fourth Down Percentage               0.0%       0.0%
Two Pt Conversions Made                 0          0
Two Pt Conversions Attempted            0          0
Two Pt Conversion Percentage         0.0%       0.0%
Offense Redzone Num                     1          1
Offense Redzone TDs                     0          1
Offense Redzone FGs                     1          0
Offense Redzone Percentage         100.0%     100.0%
Rushing Attempts                       15          9
Rushing Yards                          32         33
Rushing Average                       2.1        3.7
Rushing TDs                             0          0
Passing Yards                          63         90
Passing Completions                     6          5
Passing Attempts                       10          8
Completion Percentage               60.0%      62.5%
Passing Average                       6.3       11.3
Passing TDs                             0          1
Offensive Pass Interceptions            0          0
TOTAL OFFENSE                          95        123
Defensive Pass Interceptions            0          0
Punt Return Yards                       0          0
Kick Return Yards                      52         17
Punts                                   0          0
Punt Avg                              0.0        0.0
Fumbles                                 1          0
Fumbles Lost                            1          0
Penalties                               0          1
Penalty Yds                             0          5
Turnovers                               1          0
TIME OF POSSESSION                  11:04      07:38

Individual Stats: Bears
PASSING                        CMP  ATT  YDS  PCT   YPA SACK   TD  INT LONG RATING
Marc Bulger                      5    8   90   62  11.2    0    1    0   42  140.6

RUSHING                        ATT  YDS   AVG LONG   TD  FUM
Cedric Benson                    8   26   3.2    9    0    0
Vernand Morency                  1    7   7.0    7    0    0

RECEIVING                      REC  YDS   AVG LONG   TD DROP  YAC
Sidney Rice                      2   63  31.5   42    0    1   10
Mark Bradley                     1   19  19.0   19    0    0    6
Desmond Clark                    1    7   7.0    7    0    0    0
Bernard Berrian                  1    1   1.0    1    1    0    0

KICKING                        FGM  FGA  PCT FGSBLOCKED  XPA  XPM  PCT XPSBLOCKED KICKOFFS TOUCHBACKS
Robbie Gould                     1    1  100          0    1    1  100          0        3          1

PUNTING                        ATT  YDS   AVG LONG BLOCKS IN20 TOUCHBACKS
No stats.

KICK RETURNS                   ATT  YDS   AVG   TD LONG
Mark Bradley                     1   17  17.0    0   17

PUNT RETURNS                   ATT  YDS   AVG LONG   TD
Mark Bradley                     0    0   0.0    0    0

DEFENSE                        TOT LOSS SACK   FF FREC  YDS   TD  INT  RET   AVG DEFLECTIONS SAFETIES CTH ALLOW BIG HITS
Dedric Brown                     4    0    0    0    0    0    0    0    0   0.0           0        0         1        0
Adewale Ogunleye                 4    2    0    0    1    5    0    0    0   0.0           0        0         0        0
Brian Urlacher                   3    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Nathan Vasher                    2    0    0    0    0    0    0    0    0   0.0           0        0         2        0
Leon Hall                        2    0    0    0    0    0    0    0    0   0.0           0        0         1        0
Tommie Harris                    1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Dwight Freeney                   1    1    0    1    0    0    0    0    0   0.0           0        0         0        0
Dez Dorsey                       1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Takeo Spikes                     1    1    0    0    0    0    0    0    0   0.0           0        0         0        0
Josh Gattis                      1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Abdul Hodge                      1    0    0    0    0    0    0    0    0   0.0           0        0         0        0

BLOCKING                      PANCAKES SACKS ALLOWED
Desmond Clark                        3             0
John Tait                            3             0
Corey Hilliard                       2             0
Mark Bradley                         1             0
Jason Snelling                       1             0
Anthony Pudewell                     1             0
Deuce Lutui                          1             0


Individual Stats: Lions
PASSING                        CMP  ATT  YDS  PCT   YPA SACK   TD  INT LONG RATING
Drew Bledsoe                     6   10   63   60   6.2    0    0    0   22   78.3

RUSHING                        ATT  YDS   AVG LONG   TD  FUM
Brandon Jacobs                  12   35   2.9   11    0    0
Shawn Bryson                     1    3   3.0    3    0    0
Brian Westbrook                  1    0   0.0    0    0    0
Drew Bledsoe                     1   -6  -6.0    0    0    1

RECEIVING                      REC  YDS   AVG LONG   TD DROP  YAC
Vincent Jackson                  3   33  11.0   21    0    0    1
George Wrighster                 1   22  22.0   22    0    0    0
Reggie Williams                  2    8   4.0    7    0    0    3
Mike Furrey                      0    0   0.0    0    0    1    0

KICKING                        FGM  FGA  PCT FGSBLOCKED  XPA  XPM  PCT XPSBLOCKED KICKOFFS TOUCHBACKS
Mike Nugent                      2    2  100          0    0    0    0          0        2          1

PUNTING                        ATT  YDS   AVG LONG BLOCKS IN20 TOUCHBACKS
No stats.

KICK RETURNS                   ATT  YDS   AVG   TD LONG
Skyler Green                     2   52  26.0    0   30

PUNT RETURNS                   ATT  YDS   AVG LONG   TD
Skyler Green                     0    0   0.0    0    0

DEFENSE                        TOT LOSS SACK   FF FREC  YDS   TD  INT  RET   AVG DEFLECTIONS SAFETIES CTH ALLOW BIG HITS
Boss Bailey                      3    0    0    0    0    0    0    0    0   0.0           0        0         1        0
Ernie Sims                       3    1    0    0    0    0    0    0    0   0.0           0        0         1        0
Daniel Bullocks                  2    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Brandon Jacobs                   1    0    0    0    0    0    0    0    0   0.0           0        0         0        0
Brian Robison                    1    0    0    0    0    0    0    0    0   0.0           0        0         0        0

BLOCKING                      PANCAKES SACKS ALLOWED
Rex Tucker                           4             0
Damien Woody                         2             0
Adam Bergen                          2             0
George Wrighster                     1             0
Brandon Jacobs                       1             0
Dan Santucci                         1             0
Winston Justice                      1             0
Shawn Bryson                         1             0
Dominic Raiola                       1             0


Game Log Ends
------------------------------------------------------------

    first you read the complete file into one string

    then you can scan the file for 'keywords' or expressions
    that mark beginning of a section

    then you create new strings, substrings, out of parts of the original string

    suitable functions may be [man]strpos[/man] [man]substr[/man]


    Here I made an experiment. It works.

    I copied the code from your post, and saved it as a textfile:
    lions_at_bears.txt
    Then if I run this script ( read comments ) I get 4 substrings
    from sections of the original file.

    <?php
    
    $gamelogfile = 'lions_at_bears.txt';
    // we put all file contents into a string $def   ( default )
    $def = file_get_contents( $gamelogfile ); 
    
    $pos0 = 0;
    // search for pos where 'Game ..' starts, we begin at pos0
    $pos1 = strpos( $def, 'Game Statistics', $pos0 );
    // first substring is from pos0 with length between pos1-pos0
    $str1 = substr( $def, $pos0, $pos1-$pos0 );
    
    $pos2 = strpos( $def, 'Individual Stats', $pos1 );
    $str2 = substr( $def, $pos1, $pos2-$pos1 );
    
    // to avoid find same 'Individual ...' we start search 2 chars later
    $pos3 = strpos( $def, 'Individual Stats', $pos2+2 );
    $str3 = substr( $def, $pos2, $pos3-$pos2 );
    $pos4 = strpos( $def, 'Game Log Ends', $pos3 );
    $str4 = substr( $def, $pos3, $pos4-$pos3 );
    
    // Display
    echo '<pre>';
    echo $str1; // first part
    echo $str2; // game statistics
    echo $str3; // individual stats team1
    echo $str4; // individual stats team2
    echo '</pre>';
    
    ?>

      Ah... I see what you're doing, I think. I'll give that a whirl when I can.

        Write a Reply...