I need to print out csv file into html or put a numeric data into database:
But I need to start a loop at specific position and break it at another specific position (regex).
So I need to reprint only rows with numerical data and all columns from them.
Following is pseudo-code - not working properly:
<?php
$row = 1;
$handle = fopen("test.csv", "r");
while ($data = fgetcsv($handle, 1000, ","))
{
if (preg_match('/[Morning]/', $data[0]) === 1 // start at this rwo plus two lines down )
{
$num = count($data);
$row++;
for ($c=0; $c < $num; $c++)
{
for ($c=0; $c < $num; $c++)
{
echo $data[$c] . " ";
}
if (preg_match('/[Total Cash:]/', $data[0]) === 1)
{ break; row -1 }
}
echo "<br>";
}
}
fclose($handle); ?>
So csv goes like this:
/--some lines--/Date: 3/3/11, Morning, --blank line--- Customer No,Time,CheckNo,Total, 1234,12-45,01,20.00, 1236,1-00,03,30.00, 1240,2-00,06,30.00, --more numerical rows of data at variable length that I need to loop over-- 1500,4-00,07,22.00, ----,----,---,----, Total Cash, , , ,120.00,
/--some other lines--and it goes/
Lunch Time, ---similar like Morning above ---
Any info how to properly addrres this issue is appreciated, I can now do so many loops and regex but with this I need some more time and help. Thanks.
/[Morning]/
? You are looking for a value, that containsM
,o
,r
, ..., org
? – KingCrunch Aug 11 '11 at 16:47