Hi all,
I'm reading in a file that is generated by a mainframe job. What I'm trying to do is extract out each number ($piece), from within each "category", so that I can insert each $piece into a mysql db for each corresponding cat-type doc or cat-type line.
So far, the code below works with one exception...the last part of each line echo's out null, but yet it's detected as not null. Any ideas why piece 72 would be echo'd out? b.t.w. there are no tabs between the numbers, no newlines and a variable number of spaces between the numbers.
Input file:
REPORT NO. SOMEONE
PROGRAM ID RPT444
RUN DATE 01/29/04 INPUT CONTROL LIST
--HEADER 1-- --HEADER 2-- --HEADER 3-- --HEADER 4--
CAT TYPE DOCS/LINES DOCS/LINES DOCS/LINES DOCS/LINES TOTALS DOC/LINES
CATEGORY1 4,617 16,859 0 36 21,512
8,031 17,645 0 47 25,723
CATEGORY2 705 2,768 1,058 15 4,546
2,102 14,548 1,058 15 17,723
CATEGORY3 480 1,916 67 66 2,529
2,844 19,262 752 560 23,418
CATEGORY4 11,938 101,336 1,923 407 115,604
34,012 192,574 5,082 728 232,396
TOTAL 68,179 331,617 11,045 751 411,592
119,865 429,442 24,528 1,675 575,510
$lines = file($filePath.$fileIN);
foreach ($lines as $line) {
//**** Right now just working on 1 category for testing ****
if (stristr($line,"CATEGORY1")) {
$line = preg_replace("/CATEGORY1/","",$line);
$pieces = explode(" ",$line);
echo "Pieces Count: ".count($pieces)."\n";
for ($x=0;$x<count($pieces);$x++) {
if ($pieces[$x] != null) {
echo "Piece $x: $pieces[$x]\n";
}
}
}
}
Output is:
Pieces Count: 73
Piece 9: 4,617
Piece 17: 16,859
Piece 30: 0
Piece 45: 36
Piece 62: 21,512
Piece 72:
Why is Piece 72 echo'd out as being non null, when it is null in the file?
Also...any function I'm missing that could clean this up a bit, as far as extracting numbers only in each $line with those variable spaces?
Thanks in advance!