www.webdeveloper.com
Results 1 to 3 of 3

Thread: Need to parse a text file, saving certain columns

  1. #1
    Join Date
    Apr 2010
    Posts
    2

    Need to parse a text file, saving certain columns

    I've always browsed this site for PHP and Perl articles, but never needed to post before. anyway.

    I've got a file that contains Intro text, a table with whitespace used to separate the columns, and a summary paragraph. The only parts of the file I care about are accessing three of the columns.

    I need to access the AGC, TWC, and DWC fields below, and create a new file with only the values from those columns. I'm having difficulty figuring out how to open the file, and skip the paragraphs surrounding the data. Can anyone help me out? here's the data file

    04-22-09-NO42009

    blank text

    ---------------------------------------------------------------------------------
    HGT AGC COMP TWC DWC
    ---------------------------------------------------------------------------------
    20 33.0 234 11 222
    23 32.3 342 2 223
    43 31.0 234 2 224
    59 31.4 432 4 225
    68 30.0 564 5 226
    70 29.2 544 7 227

    Summary


    04-23-09-NO42009

    blank text

    ---------------------------------------------------------------------------------
    HGT AGC COMP TWC DWC
    ---------------------------------------------------------------------------------
    22 39.0 233 7 233
    24 38.3 343 8 234
    45 37.0 231 8 235
    54 37.4 432 5 236
    66 36.0 569 5 237
    74 35.2 544 4 238

    Summary

  2. #2
    Join Date
    Apr 2010
    Posts
    2
    edit: the columns should have more than just one space in between, but the forum collapsed the space when I posted it

  3. #3
    Join Date
    May 2010
    Location
    127.0.0.1
    Posts
    2
    I have a similar question, in the mean time here is a possible start:

    PHP Code:
    $fileName="FILENAME.TXT";
    $ft=fopen($fileName"r") or die ("Unable to open the file $filename");
    while(!
    feof($ft)){
        
    $lines1 fgets($ft);
        
    $lines3 explode(" "$lines1);
        print 
    "$lines3[0]$lines3[1]$lines3[2]<br />";
    }
    fclose($ft); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles