PHPackages                             fanatique/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. fanatique/php-fixed-length-file-parser

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

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

A parser class for handling fixed length text files in PHP

v2.1.0(2mo ago)159.3k↓33.3%8[2 PRs](https://github.com/fanatique/php-fixed-length-file-parser/pulls)MITPHPPHP &gt;=8.2CI passing

Since Mar 19Pushed 2mo ago2 watchersCompare

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

READMEChangelogDependencies (2)Versions (3)Used By (0)

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

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

[![PHP Version](https://camo.githubusercontent.com/d840cef9807c8f76051ad687841d67f4d830c84e0d83236968e53124ef6742d5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e322d3838393242462e737667)](https://www.php.net/)[![CI](https://github.com/fanatique/php-fixed-length-file-parser/actions/workflows/ci.yml/badge.svg)](https://github.com/fanatique/php-fixed-length-file-parser/actions/workflows/ci.yml)[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

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

```

Installation
------------

[](#installation)

```
composer require fanatique/php-fixed-length-file-parser
```

Features
--------

[](#features)

- Register a **chopping map** to define field positions and lengths
- Register a **pre-flight check** to filter lines before parsing
- Register a **callback** to transform each parsed line
- Supports any `callable` (closures, invokable objects, static methods, etc.)
- Memory-efficient line-by-line reading — safe for very large files

Usage
-----

[](#usage)

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

```
