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.
The text file looks like :
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
I used this code to read the complete file and display the output:
<?php
foreach(glob(somefile.txt") as $filename) {
$file = $filename;
$contents = file($file);
$string = implode("<br>",$contents);
echo $string;
echo "<br></br>";
}
?>
But I need to get only Student number, roll number and RandomAllocatedNumber from the above data.
Which would look something like:
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
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.
How can I change my simple code to get this?