PHPackages                             gugglegum/clv-rw - 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. gugglegum/clv-rw

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

gugglegum/clv-rw
================

Reader and writer for text files with constant length values

2.0.0(1mo ago)0934↓56.3%12MITPHPPHP &gt;=8.3

Since Nov 26Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/gugglegum/clv-rw)[ Packagist](https://packagist.org/packages/gugglegum/clv-rw)[ RSS](/packages/gugglegum-clv-rw/feed)WikiDiscussions master Synced today

READMEChangelog (3)Dependencies (2)Versions (4)Used By (2)

Reader &amp; Writer for text files with Constant Length Values
==============================================================

[](#reader--writer-for-text-files-with-constant-length-values)

CLV is a text-table format with fixed-width cells and no delimiter character. Each row is a text line separated by `LF` or `CRLF` (`\n` or `\r\n`). Each cell has a predefined character width, and missing characters are padded with spaces by default.

This format is mostly useful when integrating with older systems. For new services, CSV or JSON is usually a better choice. The main limitation is that values cannot be longer than their configured column width unless you explicitly enable trimming.

The library can work with both files and streams, so it can read from `STDIN`, write to `STDOUT`, or work with temporary streams such as `php://temp`.

Column widths are measured in UTF-8 characters, not bytes.

Requirements
------------

[](#requirements)

- PHP 8.3 or newer
- `ext-mbstring`

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

[](#installation)

```
composer require gugglegum/clv-rw
```

Reading
-------

[](#reading)

```
use gugglegum\ClvRw\Column;
use gugglegum\ClvRw\ColumnsSet;
use gugglegum\ClvRw\Reader;

$columns = new ColumnsSet([
    Column::create('Code', 4),
    Column::create('Name', 10),
]);

$reader = (new Reader())->open('input.clv', $columns);

foreach ($reader as $row) {
    echo $row['Code'], ': ', $row['Name'], PHP_EOL;
}

$reader->close();
```

Writing
-------

[](#writing)

```
use gugglegum\ClvRw\Column;
use gugglegum\ClvRw\ColumnsSet;
use gugglegum\ClvRw\Writer;

$columns = new ColumnsSet([
    Column::create('Code', 4),
    Column::create('Name', 10),
]);

$writer = (new Writer())->open('output.clv', $columns);
$writer->writeRow(['Code' => 'A1', 'Name' => 'Widget']);
$writer->close();
```

`Writer::open()` opens the target file in write mode and truncates existing contents. Use `Writer::assign()` if you need to write to an already opened stream, for example `STDOUT` or `php://temp`.

By default, values that exceed their column width throw an exception. You can trim them instead:

```
$writer->setTrimTooLongValues(true);
```

Examples
--------

[](#examples)

See the `example/` directory:

```
php example/reader.php
php example/reader.php | php example/writer.php
```

Line Endings
------------

[](#line-endings)

The reader handles `LF` and `CRLF` line endings. Classic Mac `CR`-only files should be normalized before reading. PHP's `auto_detect_line_endings` option is deprecated, so it is better not to rely on it for new code.

Exceptions
----------

[](#exceptions)

Package errors are thrown as `gugglegum\ClvRw\Exception`, which extends PHP's `RuntimeException`.

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance91

Actively maintained with recent releases

Popularity18

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity79

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~1367 days

Total

3

Last Release

43d ago

Major Versions

1.0.1 → 2.0.02026-05-22

PHP version history (2 changes)1.0.0PHP &gt;=7.0.0

2.0.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c7fbb933ba217a413e632183e6061f81bd1d285bb86efa82289977038577d88?d=identicon)[gugglegum](/maintainers/gugglegum)

---

Top Contributors

[![gugglegum](https://avatars.githubusercontent.com/u/1580712?v=4)](https://github.com/gugglegum "gugglegum (17 commits)")

---

Tags

parserwriterreadertexttablecolumnsfixed lengthcellsfixed sizeconstant sizeconstant length

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gugglegum-clv-rw/health.svg)

```
[![Health](https://phpackages.com/badges/gugglegum-clv-rw/health.svg)](https://phpackages.com/packages/gugglegum-clv-rw)
```

###  Alternatives

[bcncommerce/json-stream

A bundle of tools to work with JSON in PHP

682.3M3](/packages/bcncommerce-json-stream)[veewee/xml

XML without worries

1837.0M39](/packages/veewee-xml)[dallgoot/yaml

Provides loader, dumper and an API for YAML content. Loader builds to equivalent data types in PHP 8.x

43251.8k9](/packages/dallgoot-yaml)[creof/wkb-parser

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

605.3M16](/packages/creof-wkb-parser)[creof/geo-parser

Parser for geography coordinate strings

624.6M15](/packages/creof-geo-parser)[creof/wkt-parser

Parser for well-known text (WKT) object strings

545.0M16](/packages/creof-wkt-parser)

PHPackages © 2026

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