As far as I understand you have a file with a header followed by a number of recordsets. Then you have to adjust the offset accordingly while processing your data:
$header = unpack ($header_format, $data);
$numRecords = $header['L# of Records'];
$offset = $header['SHeader Size'];
$recordSize = $header['SRecord Size'];
for ($i = 0; $i < $numRecords; $i++)
{
$record = unpack ($record_format, $data, $offset);
$offset += $recordSize;
}
This requires setting up the
unpack()
format strings properly so that they match the data in the file. The
CTime
field for example looks suspicious because I have no idea how a time value can be stored in 8 bits.
[EDIT]
If there are multiple packets beginning with a header you have to put the above into an outer loop:
$offset = 0;
$data_len = strlen($data);
while ($offset < $data_len)
{
$header = unpack ($header_format, $data, $offset);
$numRecords = $header['L# of Records'];
$recordSize = $header['SRecord Size'];
$offset += $header['SHeader Size'];
for ($i = 0; $i < $numRecords; $i++)
{
$record = unpack ($record_format, $data, $offset);
$offset += $recordSize;
}
}
[/EDIT]