Hi,
I have a text based report which I need to parse and put the info into textfile and then upload to a database. The report is in the following format:
Date : 05/04/-01 [15:45]
Service: Live
Field1 | Field2 | Field3 | Field4 | Field5
-------+--------+--------+--------+-------
00001 | CODE01 | text | 456587 | 170
00002 | CODE02 | text | 456588 | 170
00003 | CODE02 | text | 456589 | 170
etc....
Date : 05/04/-01 [15:45]
Service: Live
Page 2
Field1 | Field2 | Field3 | Field4 | Field5
-------+--------+--------+--------+-------
00080 | CODE80 | text | 456587 | 170
00081 | CODE81 | text | 456588 | 170
00082 | CODE81 | text | 456589 | 170
etc....
This is the code I am using at the moment to parse the info into a textfile:
<?php
$data = file("report.txt");
$fp = fopen("parsereport.txt", "w");
for ($i=8;$i < count($data);$i++) {
$rawdata = explode("|",$data[$i]);
for ($x=1;$x < (count($rawdata) - 1);$x++) {
fwrite($fp, trim($rawdata[$x]) . ",");
}
fwrite($fp, "\n");
}
?>
The problem is it misses out the first & last field on each line.
ie/ Sample data from text file
CODE01,text,456587
I think this is to do with
explode("|",$data[$i]);
The other problem is with the new pages having header information on them, I need to strip this out as well.
Anyone got any ideas how to solve these problems?
I would appreciate any help on this.
Cheers
Mike