PHPackages                             talkingbit/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. talkingbit/csv

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

talkingbit/csv
==============

Read and Write CSV files

v1.0.2(5y ago)881[2 issues](https://github.com/franiglesias/csv/issues)MITPHPPHP &gt;=7.1CI failing

Since Jun 24Pushed 4y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

csv
===

[](#csv)

A package with classes to manage reading and writing of csv files.

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

[](#installation)

Add to your project using composer:

```
composer require talkingbit/csv

```

Basic usage
-----------

[](#basic-usage)

### Reader

[](#reader)

Reader allows us to read the contents of a given file in the file system. Contents are yielded using a Generator. Typical usage could be like this. Rows will be read as plain arrays.

```
use TalkingBit\Csv\Reader\Reader;

$reader = new Reader();
$filePath = '/path/to/file.csv';
$rows = $reader
    ->fromFile($filePath)
    ->readAll();

foreach ($rows as $row) {
    // Do whatever you need
}
```

If the file has csv headers, you can use the following setup, so rows will be read as associative arrays:

```
use TalkingBit\Csv\Reader\Reader;

$reader = new Reader();
$filePath = '/path/to/file.csv';
$rows = $reader
    ->fromFile($filePath)
    ->withHeaders()
    ->readAll();

foreach ($rows as $row) {
    // Do whatever you need
}
```

Also, you can map rows to a simple Dto, provided that all relevant fields are public:

```
use TalkingBit\Csv\Reader\Reader;
use TalkingBit\Csv\Reader\Mapper\DtoMapper;

$reader = new Reader();
$filePath = '/path/to/file.csv';
$rows = $reader
    ->fromFile($filePath)
    ->withHeaders()
    ->usingMapper(new DtoMapper(MyDto::class))
    ->readAll();

foreach ($rows as $row) {
    // Do whatever you need
}
```

### Writer

[](#writer)

Writer allows us to write data to a CSV file.

A row can be a plain array:

```
use TalkingBit\Csv\Writer\Writer;

$writer = new Writer();
$writer
    ->toFile('/path/to/file.csv')
    ->writeRow([123, 'My name']);
```

A row can be an associative array. In this case, keys will be used as CSV headers.

```
use TalkingBit\Csv\Writer\Writer;

$writer = new Writer();
$writer
    ->toFile('/path/to/file.csv')
    ->writeRow(['id' => 123, 'name' => 'My name']);
```

Also, you can write Dto directly to CSV files. Dtos will be treated as if they were associative arrays.

```
use TalkingBit\Csv\Writer\Writer;

$writer = new Writer();

$dto = new MyDto();
$dto->id = 123;
$dto->name = 'My name';

$writer
    ->toFile('/path/to/file.csv')
    ->writeRow($dto);
```

Configuration
-------------

[](#configuration)

You can customize delimiters and enclosure characters:

```
$writer
    ->toFile('/path/to/file.csv')
    ->withDelimiter(',')
    ->withEnclosure('"')
    ->writeRow($dto);
```

Custom Mappers for Reader
-------------------------

[](#custom-mappers-for-reader)

You can create custom mappers for the Reader implementing the following interface:

```
interface RowMapperInterface
{
    public function map(array $line, ?array $headers = null);
}
```

The `$line` parameter contains the row data from the file. The `$headers` contains csv headers if found. You can return any type, so you are free to do things like:

- Build application objects.
- Make calculations with input data.
- Validate input data.

Contribute
----------

[](#contribute)

Feel free to open issues or pull requests.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

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

Total

4

Last Release

2153d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4b96113675efe6129770582f394157053ac9b02521b846add56b32dfab81d55b?d=identicon)[franiglesias](/maintainers/franiglesias)

---

Top Contributors

[![franiglesias](https://avatars.githubusercontent.com/u/16079996?v=4)](https://github.com/franiglesias "franiglesias (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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