I would suggest defining an array that has the start and length of each field, that you want to extract:
// just specify the fields you need:
$fields = array(
array(0, 6), // (start, length)
array(6, 3),
array(12, 22),
array(55, 6)
);
$file = file('datafile.txt') or die('couldn't read file');
$data = array();
foreach($file as $key => $line)
{
foreach($fields as $ix => $field)
{
$data[$key][$ix] = substr($line, $field[0], $field[1]);
}
}
At this point $data should be a 2-dim array with your data, something like:
array (
[0] => array (
[0] => value,
[1] => value,
<...etc....>
),
[1] => array (
[0] => value,
[1] => value,
<...etc....>
),
<...etc....>
)
You might want to specify the fields as an associative array to help with readability:
$fields = array(
'field_name_1' => array(0, 6), // (start, length)
'field_name_2' => array(6, 3),
// <...etc....>