PHPackages                             tpmanc/csvhelper - 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. tpmanc/csvhelper

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

tpmanc/csvhelper
================

Helper class for working with CSV files

1.1.1(9y ago)0448BSD-3-ClausePHPPHP &gt;=5.4.0

Since Oct 7Pushed 9y ago2 watchersCompare

[ Source](https://github.com/tpmanc/csv-helper)[ Packagist](https://packagist.org/packages/tpmanc/csvhelper)[ Docs](https://github.com/tpmanc/csv-helper)[ RSS](/packages/tpmanc-csvhelper/feed)WikiDiscussions master Synced yesterday

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

CSV Helper
==========

[](#csv-helper)

Helper class for working with CSV files.

Install via Composer
--------------------

[](#install-via-composer)

Run the following command

```
$ composer require tpmanc/csvhelper "*"
```

or add

```
$ "tpmanc/csvhelper": "*"
```

to the require section of your `composer.json` file.

File reading
------------

[](#file-reading)

file.csv:

```
Russia;Moscow;
France;Paris;
Great Gritain;London;

```

```
use tpmanc\csvhelper\CsvHelper;

...

CsvHelper::open('files/file.csv')->parse(function($line) {
    echo $line[0] . ': ' . $line[1];
});
```

Result:

```
Russia: Moscow
France: Paris
Great Gritain: London

```

### Custom delimiter

[](#custom-delimiter)

file.csv:

```
Russia|Moscow|
France|Paris|
Great Gritain|London|

```

```
use tpmanc\csvhelper\CsvHelper;

...

CsvHelper::open('files/file.csv')->delimiter('|')->parse(function($line) {
    echo $line[0] . ': ' . $line[1];
});
```

Result:

```
Russia: Moscow
France: Paris
Great Gritain: London

```

### Change encoding

[](#change-encoding)

```
use tpmanc\csvhelper\CsvHelper;

...

CsvHelper::open('files/file.csv')->encode('cp1251', 'utf-8')->parse(function($line) {
    echo $line[0] . ': ' . $line[1];
});
```

### Offset and limit

[](#offset-and-limit)

file.csv:

```
Russia;Moscow;
France;Paris;
Great Gritain;London;

```

```
use tpmanc\csvhelper\CsvHelper;

...

CsvHelper::open('files/file.csv')->offset(1)->limit(1)->parse(function($line) {
    echo $line[0] . ': ' . $line[1];
});
```

Result:

```
France: Paris

```

### Using variables from the parent scope

[](#using-variables-from-the-parent-scope)

file.csv:

```
Russia;Moscow;
France;Paris;
Great Gritain;London;

```

```
use tpmanc\csvhelper\CsvHelper;

...

$lineCount = 0;
$array = [];
CsvHelper::open('files/file.csv')->parse(function($line) use(&$lineCount, &$array) {
    $lineCount++;
    $array[] = $line[0];
});
echo $lineCount;
echo $array[0];
echo $array[1];
```

Result:

```
3
Russia
France

```

Create new file
---------------

[](#create-new-file)

```
use tpmanc\csvhelper\CsvHelper;

...

$file = CsvHelper::create()->delimiter(';');

$file->encode('cp1251', 'utf-8'); // change encoding
$file->addLine('1.;France;'); // add row to file by string
$file->addLine([
    2,
    'Germany'
]); // add row to file by array

$file->save('./new-file.csv');
```

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

3607d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6450943?v=4)[Chukantsev Nikita](/maintainers/tpmanc)[@tpmanc](https://github.com/tpmanc)

---

Top Contributors

[![tpmanc](https://avatars.githubusercontent.com/u/6450943?v=4)](https://github.com/tpmanc "tpmanc (13 commits)")

---

Tags

csvcsv-filesphphelpercsvreading

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tpmanc-csvhelper/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k132.8M889](/packages/barryvdh-laravel-ide-helper)[firefly-iii/data-importer

Firefly III Data Import Tool.

8035.8k](/packages/firefly-iii-data-importer)[bryanjhv/slim-session

Session middleware and helper for Slim framework 4.

2411.0M16](/packages/bryanjhv-slim-session)[mtownsend/read-time

A PHP package to show users how long it takes to read content.

281641.8k2](/packages/mtownsend-read-time)[beste/json

A simple JSON helper to decode and encode JSON

4226.8M3](/packages/beste-json)[chillerlan/php-settings-container

A container class for immutable settings objects. Not a DI container.

3435.1M23](/packages/chillerlan-php-settings-container)

PHPackages © 2026

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