PHPackages                             cego/php-fixed-length-file-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. cego/php-fixed-length-file-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

cego/php-fixed-length-file-parser
=================================

A parser class for handling fixed length text files in PHP

2.0.0(5y ago)018.7k↓58.2%MITPHPPHP &gt;=5.3.0

Since May 2Pushed 5y agoCompare

[ Source](https://github.com/cego/php-fixed-length-file-parser)[ Packagist](https://packagist.org/packages/cego/php-fixed-length-file-parser)[ Docs](https://github.com/fanatique/php-fixed-length-file-parser)[ RSS](/packages/cego-php-fixed-length-file-parser/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)DependenciesVersions (5)Used By (0)

php-fixed-length-file-parser
============================

[](#php-fixed-length-file-parser)

A parser class for handling fixed length text files in PHP.

Fixed Length Files (aka poor man's CSV) are plain text files with one data set per row *but without any delimiter*.

```
01Amy  BLUES
02Bob  REDS
...

```

Features
--------

[](#features)

This class provides a rather comfortable way to handle this type of file on PHP.

You can:

- register a pre flight check to determine whether or not a row has to be parsed
- register a callback to handle each line
- register a chopping map which transforms each row into an assiciative array

Usage
-----

[](#usage)

The following example shows how to transform a fixed length file into an associative array. The working example can be found in `example/parsing.php`.

```
$parser = new \Fanatique\Parser\FixedLengthFileParser();

//Set the chopping map (aka where to extract the fields)
$parser->setChoppingMap(array(
  array('field_name' => 'id', 'start' => 0, 'length' => 2),
  array('field_name' => 'name', 'start' => 2, 'length' => 5),
  array('field_name' => 'team', 'start' => 7, 'length' => 5),
));

```

`field_name` and `length` are required and `start` is an optional parameter. If `start` is omitted, it will be set to the `start` plus `length` value of the previous map entry.

```
//Set the absolute path to the file
$parser->setFilePath(__DIR__ . '/example.dat');

//Parse the file
try {
  $parser->parse();
} catch (\Fanatique\Parser\ParserException $e) {
  echo 'ERROR - ' . $e->getMessage() . PHP_EOL;
  exit(1);
}

//Get the content
var_dump($parser->getContent());

```

### Registering a pre flight check

[](#registering-a-pre-flight-check)

A pre flight check can be registered to be applied to each row *before* it is parsed. The closure needs to return a boolean value with:

- `false`: line needs not to be parsed
- `true`: parse line

This example ignores any line which md5 sum is `f23f81318ef24f1ba4df4781d79b7849`:

```
$linesToIgnore = array('f23f81318ef24f1ba4df4781d79b7849');
$parser->setPreflightCheck(function($currentLineStr) use($linesToIgnore) {
          if (in_array(md5($currentLineStr), $linesToIgnore)) {
              //Ignore line
              $ret = false;
          } else {
              //Parse line
              $ret = true;
          }
          return $ret;
      }
);

```

### Registering a callback

[](#registering-a-callback)

Finally you can register a callback which is applied to each parsed line and allows you to process it. The closure gets the parsed line as an array and it is expected to return an array of the same format.

```
$parser->setCallback(function(array $currentLine) {
            $currentLine['team'] = ucwords(strtolower($currentLine['team']));
            return $currentLine;
        }
);

```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 73.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~354 days

Total

4

Last Release

1913d ago

Major Versions

1.0.2 → 2.0.02021-03-30

### Community

Maintainers

![](https://www.gravatar.com/avatar/3d79d2046d4c647d13783eaedebc0044f9e824fd211e2b23281aaf727222e3f2?d=identicon)[cego](/maintainers/cego)

---

Top Contributors

[![friis-koder](https://avatars.githubusercontent.com/u/29247489?v=4)](https://github.com/friis-koder "friis-koder (14 commits)")[![manuelbieh](https://avatars.githubusercontent.com/u/239546?v=4)](https://github.com/manuelbieh "manuelbieh (4 commits)")[![nbj](https://avatars.githubusercontent.com/u/8373450?v=4)](https://github.com/nbj "nbj (1 commits)")

---

Tags

phpparsertextfixed length

### Embed Badge

![Health badge](/badges/cego-php-fixed-length-file-parser/health.svg)

```
[![Health](https://phpackages.com/badges/cego-php-fixed-length-file-parser/health.svg)](https://phpackages.com/packages/cego-php-fixed-length-file-parser)
```

###  Alternatives

[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k942.7M149](/packages/doctrine-lexer)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1891.3M15](/packages/simplehtmldom-simplehtmldom)[creof/wkb-parser

Parser for well-known binary (WKB/EWKB) object data

605.3M16](/packages/creof-wkb-parser)[fanatique/php-fixed-length-file-parser

A parser class for handling fixed length text files in PHP

159.5k](/packages/fanatique-php-fixed-length-file-parser)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23790.9k2](/packages/corveda-php-sandbox)[leonelquinteros/php-toml

PHP parser for TOML language ( https://github.com/toml-lang/toml )

276.8k](/packages/leonelquinteros-php-toml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
