title: Reading data from text file and forming a table using php
body: <p>I have a text file that contains data that looks like being formatted in a table. But they are just ordered lines of text made to resemble a table. I am trying to read the text file, get only some of data and form a HTML table.</p>
  
  <p>The text file looks like :</p>
  
  <pre><code>Class 1:
  S.No RollNumber Name RandomAllocatedNumber Overall Result
  ---- ---------- ---- --------------------- --------------
  1 ABC-BYT-M56-8T Sam Jackson NBV26173GHS Pass
  2 BNS-SUD-H72-7Y Mario Javi  HAS12824SAD Pass
  
  Class 2:
  S.No RollNumber Name RandomAllocatedNumber Overall Result
  ---- ---------- ---- --------------------- --------------
  1 POW-AVE-S36-7C Matt Stepson GSA22343GFS Pass
  2 EWG-JAS-T12-3R Taylor Xavier  EWF54524EAD Pass
  </code></pre>
  
  <p>I used this code to read the complete file and display the output:</p>
  
  <pre><code>&lt;?php
  foreach(glob(somefile.txt") as $filename) {
  $file = $filename;
  $contents = file($file);
  $string = implode("&lt;br&gt;",$contents);
  echo $string;
  echo "&lt;br&gt;&lt;/br&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p>But I need to get only Student number, roll number and RandomAllocatedNumber from the above data.</p>
  
  <p>Which would look something like:</p>
  
  <pre><code>ClassNo |RollNumber     |RandomAllocatedNumber
  
  1       |ABC-BYT-M56-8T |NBV26173GHS
  1       |BNS-SUD-H72-7Y |HAS12824SAD
  2       |POW-AVE-S36-7C |GSA22343GFS
  2       |EWG-JAS-T12-3R |EWF54524EAD
  </code></pre>
  
  <p>The above table is what I look to be displayed in the php page rather than totally reading the lines and displaying the whole file.</p>
  
  <p>How can I change my simple code to get this?</p>