PHPackages                             axelero/fixed-width - 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. axelero/fixed-width

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

axelero/fixed-width
===================

A library to parse and build fixed-width strings

1.01(9y ago)237.2k—5.6%2MITPHPPHP &gt;=5.5.9

Since Jan 9Pushed 7y ago5 watchersCompare

[ Source](https://github.com/axelero/fixed-width)[ Packagist](https://packagist.org/packages/axelero/fixed-width)[ Docs](http://www.axelero.it)[ RSS](/packages/axelero-fixed-width/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (1)Versions (2)Used By (0)

FixedWidth
==========

[](#fixedwidth)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b08b9e08f265a84d434cdcfb615be9ca93025108768816e0000f07dc017c1eac/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6178656c65726f2f66697865642d77696474682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/axelero/fixed-width)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/b793ede308a17ae431c2c620d6ca57afd60d103de48a2c9089eeeae1d8e3e1da/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6178656c65726f2f66697865642d77696474682f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/axelero/fixed-width)[![Total Downloads](https://camo.githubusercontent.com/82d2bb28ab05bb5fd7832a13616b4fa4c8ae4cf4e3fc574322ac7a753464e515/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6178656c65726f2f66697865642d77696474682e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/axelero/fixed-width)[![Coverage Status](https://camo.githubusercontent.com/f5178c4e76dcf5b99f9f25e26be3c501f968677ba5935ae6421f669301f326a6/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6178656c65726f2f66697865642d77696474682e737667)](https://coveralls.io/r/axelero/fixed-width)

A simple library to read and write fixed width file. It's a partial port from [this python library](https://github.com/ShawnMilo/fixedwidth), with the aim to be simple, stable and consistent.

Install
-------

[](#install)

Via Composer

```
$ composer require axelero/fixed-width
```

Usage
-----

[](#usage)

You can read values from arbitrary strings:

```
$config = [
'a' => [
    'type' => 'string',
    'start' => 3,
    'length' => 10
],
// numeric indexes of the config array will be ignored
[
    'type' => 'string',
    'start' => 13,
    'end' => 13
],
'b' => [
    'type' => 'string',
    'start' => 14,
    'end' => 17
]
];

$obj = new FixedWidth($config);

$line = '12345678901234567890';
$record = $obj->readLine($line); // ['a' => '3456789012','b' => '4567',]
```

You can write arrays into fixed-width strings:

```
$config = [
    'a' => [
        'type' => 'string',
        'start' => 1,
        'end' => 5
    ],
    'b' => [
        'type' => 'integer',
        'start' => 6,
        'end' => 10
    ]
];

$obj = new FixedWidth($config);

$data = ['a' => 'xxx', 'b' => 42];
$string = $obj->writeLine($data); // 'xxx  00042'
```

The possible configuration values for each field are:

- **type**: string|integer
- **alignment**: left|right *(defaults to left for string, right for integers)*
- **padding**: charachter to use to fill the missing space *(defaults to '' for string, '0' for integers)*
- **default**: what to write when an array field is missing *(defaults to '' for string, '0' for integers)*

Testing
-------

[](#testing)

```
$ phpunit
```

Contributing
------------

[](#contributing)

You are welcome to send any PR. Please make sure the tests pass. Please try to keep the code PSR compliant (in the root of the project lies a .php\_cs config file for that).

Credits
-------

[](#credits)

- [axélero](https://github.com/axelero)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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

Unknown

Total

1

Last Release

3417d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0661f7f5f46f7e2d21e82de22e01c9338bf3d0332b68e078f6cb168ac48775b4?d=identicon)[fcamp](/maintainers/fcamp)

---

Top Contributors

[![tacone](https://avatars.githubusercontent.com/u/659801?v=4)](https://github.com/tacone "tacone (8 commits)")[![eiriksm](https://avatars.githubusercontent.com/u/865153?v=4)](https://github.com/eiriksm "eiriksm (1 commits)")[![maurodalatri](https://avatars.githubusercontent.com/u/3215471?v=4)](https://github.com/maurodalatri "maurodalatri (1 commits)")

---

Tags

fixed-width

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/axelero-fixed-width/health.svg)

```
[![Health](https://phpackages.com/badges/axelero-fixed-width/health.svg)](https://phpackages.com/packages/axelero-fixed-width)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[meyfa/php-svg

Read, edit, write, and render SVG files with PHP

54613.9M42](/packages/meyfa-php-svg)

PHPackages © 2026

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