PHPackages                             mehr-it/csv - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mehr-it/csv

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mehr-it/csv
===========

Advanced CSV reader and writer for PHP

1.10.0(2y ago)010.2k—0%MITPHPPHP &gt;=7.1.0CI failing

Since Apr 8Pushed 2y agoCompare

[ Source](https://github.com/mehr-it/csv)[ Packagist](https://packagist.org/packages/mehr-it/csv)[ RSS](/packages/mehr-it-csv/feed)WikiDiscussions master Synced 1mo ago

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

Advanced CSV reader and writer for PHP
======================================

[](#advanced-csv-reader-and-writer-for-php)

This library aims to offer advanced support for CSV in PHP. This includes charset conversions, proper handling of escape sequences and byte order marks (for UTF-8, UTF-16 and UTF-32).

The CSV writer also supports "always quoting" and custom line-breaks (EOL).

Writer usage
------------

[](#writer-usage)

Following example is quite self-explaining:

```
$writer = new CsvWriter();
$writer
	->setDelimiter(';')
	->setEnclosure("'")
	->setEscape('\\')
	->setAlwaysQuote(true)
	->open($resource)
	->writeLine(['a', 'b', 'c'])
	->close();

```

You may also pass your data as associative array with column keys if you define columns first. This allows to omit empty columns:

```
$writer = new CsvWriter();
$writer
	->open($resource)
	->columns(['a' => 'Col A', 'b' => 'Col B', 'c' => 'Col C'])
	->writeData(['a' => 15, 'b' => 16, 'c' => 17])
	->writeData(['a' => 15, 'b' => 16])
	->close();

```

Reader usage
------------

[](#reader-usage)

```
$reader = new CsvReader();
$reader
    ->setDelimiter(';')
    ->setEnclosure("'")
    ->setEscape('\\')
    ->open($resource);

while (($line = $reader->readLine()) !== false) {
    var_dump($line);
}

$reader->close();

```

To receive associative arrays with column keys, columns can be read from first line and use the `readData()`method:

```
$reader = new CsvReader();
$row = $reader
    ->open($resource)
    ->readColumns()
    ->readData();

```

If columns are not present in file, they can be set manually:

```
$reader = new CsvReader();
$row = $reader
    ->open($resource)
    ->setColumns(['a', 'b'])
    ->readData();

```

### Casting values

[](#casting-values)

Following example demonstrates the usage of casts, for easy reading data types:

```
 $reader = new CsvReader();
 $row = $reader
     ->open($resource)
     ->setColumns(['a', 'b', 'c', 'd', 'e'])
     ->setCasts(
        'a' => 'number',
        'b' => 'json',
        'c' => 'split:|'
        'd' => function($v) {
            return 'x-' . $v;
        },
        'e' => 'number:,:.',
     );
     ->readData();

```

If a value cannot be casted, `null` will be returned for the field.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity62

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 ~118 days

Recently: every ~278 days

Total

14

Last Release

1057d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/44973729?v=4)[mehr.IT GmbH](/maintainers/mehr-it)[@mehr-it](https://github.com/mehr-it)

---

Top Contributors

[![chmgr](https://avatars.githubusercontent.com/u/94837732?v=4)](https://github.com/chmgr "chmgr (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mehr-it-csv/health.svg)

```
[![Health](https://phpackages.com/badges/mehr-it-csv/health.svg)](https://phpackages.com/packages/mehr-it-csv)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[laragraph/utils

Utilities for using GraphQL with Laravel

2113.8M7](/packages/laragraph-utils)[thenextweb/passgenerator

A Laravel package to create Apple Wallet (old Passbook) compatible tickets.

297435.6k](/packages/thenextweb-passgenerator)[firefly-iii/data-importer

Firefly III Data Import Tool.

7545.8k](/packages/firefly-iii-data-importer)[wyrihaximus/html-compress

Compress/minify your HTML

841.6M31](/packages/wyrihaximus-html-compress)[keepsuit/laravel-temporal

Laravel temporal.io

4875.0k](/packages/keepsuit-laravel-temporal)

PHPackages © 2026

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