Yes I'm looking to parse a tab delimited file. I've had experience with tab delimited files before, but none with a unusefull string in the first line:

Eg of the first few lines:

Updated: Wed, 13 Aug 2003 20:12:19 GMT
a1b	M.	15100458133.0	2336	15768	166074.48
1308c	EST	970757036.0	43	450	5657.04
16ebe	TGC	77990803385.0	4599	46461	456377.47
16ede	TGc	1089275918.0	38	1186	17048.95

Typicaly the files I'm use to parsing are like so:

M.	none	DE	15.191444	2376	15896	166710.88
WBL	ZUSES_HIRN	DE	178.942071	14645	170761	1675795.05
eggi	none	DE	283.005739	37203	197628	1605127.38
jeff	CHECKMATES	no	0.008728	3	36	328.77

and the code I use to parse them are as such:

while ($userinfo = fscanf ($file, "%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\n]\n")){
         list ($name, $team, $country, $nodes_processed, $jobs_accepted, $jobs_processed, $cpu_time) = $userinfo;
}

Would anyone have a suggestion on how to write a script to parse the first example (skipping the first line with the date)?

    <?php
       $file = fopen('tabFile.txt'. 'r');
    
       $line = fgets($file, 4096);  // Read first line
       $lines_array = array();
    
       while (!feof($file)) {
          $lines_array[] = preg_split("/[\t]+/", fgets($file, 4096));
       }
    ?>
    

      Seems to be working, but how do I access the values from the array? I added a:

      echo "$lines_array[0]<br>";

      To the end to see what data was in it, but it just displays "Array" to the screen.

        Because $lines_array[0] is an array. $lines_array[0][0], $lines_array[0][1], etc.

        echo $lines_array[0][0]."<br>";

          First 5 lines of the rtstats.txt file:

          Updated: Wed, 13 Aug 2003 20:12:19 GMT
          a1b	M.	15100458133.0	2336	15768	166074.48
          1308c	EST	970757036.0	43	450	5657.04
          16ebe	TGC	77990803385.0	4599	46461	456377.47
          16ede	TGc	1089275918.0	38	1186	17048.95
          

          The php code:

          $file = fopen ("rtstats.txt","r");
          $line = fgets($file, 4096);  // Read first line
          $lines_array = array();
          while (!feof($file)) {
                  $lines_array[] = preg_split("/[\t]+/", fgets($file, 4096));
                  echo "$lines_array[0][0], $lines_array[0][1], $lines_array[0][2], $lines_array[0][3], $lines_array[0][4], $lines_array[0][5]<br>";
          }
          

          The result:

          Array[0], Array[1], Array[2], Array[3], Array[4], Array[5]
          Array[0], Array[1], Array[2], Array[3], Array[4], Array[5]
          Array[0], Array[1], Array[2], Array[3], Array[4], Array[5]
          Array[0], Array[1], Array[2], Array[3], Array[4], Array[5]
          Array[0], Array[1], Array[2], Array[3], Array[4], Array[5]
          

          😕

            Basicaly what I'm doing is trying to make sure the array is actualy storing the data, because the info is going into a sql database. Was there some extra code I'm needing to add or do I have a small typo somewhere?

              got it to work with:

              $file = fopen ("rtstats.txt","r");
              $line = fgets($file, 4096);  // Read first line
              while ($userinfo = fscanf ($file, "%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\t]\t%[^\n]\n")){
                      list ($data, $name, $nodes_processed, $jobs_accepted, $jobs_processed, $cpu_time) = $userinfo;
                      echo "$name<br>";
              }
              

                well, this is what I use:

                $link = file("files.dat"); 
                for ($i=sizeof($link)-1; $i>=0; $i--){
                 list($url, $flink, $size, $timestamp) = split("\t", $link[$i]); 
                
                 $date = date("m-d-y g:i:s a", $timestamp);
                // etc..
                
                }
                
                  Write a Reply...