[0-9a-f]{40}) (?P[a-z]+) (?P\d+)$/', $s, $m)) { throw new Exception("Unexpected format: *$s*"); }; $current = array( 'hash' => $m['hash'], 'type' => $m['type'], 'data' => fread($git, $m['size']), ); //print_r($current); $data[] = $current; fgets($git); } pclose($git); print_r($data);