PHPackages                             inwebo/csv-reader - 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. [PDF &amp; Document Generation](/categories/documents)
4. /
5. inwebo/csv-reader

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

inwebo/csv-reader
=================

This PHP class, provides a simple yet powerful way to read and process CSV files. Built as an extension of PHP's SplFileObject, it offers advanced features like column name mapping, data filtering, and sanitization to streamline your CSV processing tasks.

1.0.3(1mo ago)32GPL-3.0-or-laterPHPPHP ^8.3CI passing

Since Sep 4Pushed 1mo agoCompare

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

READMEChangelogDependencies (4)Versions (6)Used By (0)

PHP CSV Reader
==============

[](#php-csv-reader)

[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/d5dbd1eb61734734065520f8d46c079290ac29e9c688680402c5e6c9142cc656/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f696e7765626f2f6373762d7265616465722f2e676974687562253246776f726b666c6f77732532466c6962726172792e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d5dbd1eb61734734065520f8d46c079290ac29e9c688680402c5e6c9142cc656/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f696e7765626f2f6373762d7265616465722f2e676974687562253246776f726b666c6f77732532466c6962726172792e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)[![Packagist Version](https://camo.githubusercontent.com/d15c2bb030a0f523d4d2a1fb73edfb899126aaea5b99f25b9bc00f3e45bcf13d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e7765626f2f6373762d7265616465723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d15c2bb030a0f523d4d2a1fb73edfb899126aaea5b99f25b9bc00f3e45bcf13d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e7765626f2f6373762d7265616465723f7374796c653d666c61742d737175617265)[![Packagist Downloads](https://camo.githubusercontent.com/a0e440d149ddee686dcd741b09d2cc29cef965a54de6116fdbd8ad4d7d2b018b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f696e7765626f2f6373762d7265616465723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a0e440d149ddee686dcd741b09d2cc29cef965a54de6116fdbd8ad4d7d2b018b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f696e7765626f2f6373762d7265616465723f7374796c653d666c61742d737175617265)

This PHP class, `Inwebo\Csv\Reader`, provides a simple yet powerful way to read and process CSV files. Built as an extension of PHP's `SplFileObject`, it offers advanced features like **column name mapping**, **data filtering**, and **normalization** to streamline your CSV processing tasks.

---

### Key Features

[](#key-features)

- **Column Name Mapping**: Automatically maps each line's data to an associative array using the CSV header as keys, making your code more readable and maintainable.
- **Data normalization**: Apply one or more callable functions to each line to clean and format the data before it's used.
- **Data Filtering**: Use callable functions to validate and filter out rows that don't meet your criteria.
- **Generator-based Iteration**: Process large files efficiently using a `Generator` to iterate over lines without consuming too much memory.
- **Inherits `SplFileObject`**: Leverage all the native features and performance benefits of `SplFileObject` for file handling.

---

### Installation

[](#installation)

```
  composer req inwebo/csv-reader
```

Tests
-----

[](#tests)

```
  composer phpunit
```

PhpStan
-------

[](#phpstan)

```
  composer phpstan
```

> Level 10

---

### Usage

[](#usage)

#### Basic Reading

[](#basic-reading)

To get started, simply instantiate the `Reader` class with the path to your CSV file. By default, it assumes the first row contains column names.

```
use Inwebo\Csv\Reader;

$reader = new Reader('path/to/your/file.csv');

foreach ($reader->rows() as $row) {
    // $row will be an associative array, e.g., ['column_name' => 'value']
    print_r($row);
}
```

#### Disabling Column Names

[](#disabling-column-names)

If your CSV file does not have a header row, you can disable the column name mapping by setting the `hasColName` parameter to `false`.

```
use Inwebo\Csv\Reader;

$reader = new Reader('path/to/your/file.csv', hasColName: false);

foreach ($reader->rows() as $row) {
    // $row will be a numeric array, e.g., ['value1', 'value2']
    print_r($row);
}
```

---

#### Manual Column Mapping

[](#manual-column-mapping)

For files without a header, you can manually define column names using the `mapIndexToColName()` method. This allows you to treat the data as an associative array even without a header row.

```
use Inwebo\Csv\Reader;

$reader = new Reader('path/to/your/file.csv', hasColName: false);

$reader
    ->setHeader(0, 'id')
    ->setHeader(1, 'name')
    ->setHeader(2, 'email');

foreach ($reader->rows() as $row) {
    // $row will be an associative array, e.g., ['id' => '1', 'name' => 'John Doe', 'email' => 'john@example.com']
    print_r($row);
}
```

---

### Advanced Usage: Sanitizers and Filters

[](#advanced-usage-sanitizers-and-filters)

You can add multiple sanitizers and filters to your `Reader` instance. They are executed sequentially in the order they are added.

#### Sanitizers

[](#sanitizers)

Sanitizers are used to modify the data. The callback receives the line array by reference, allowing you to directly alter its values.

```
use Inwebo\Csv\Reader;

$reader = new Reader('path/to/your/file.csv');

// Add a sanitizer to trim whitespace from all values
$reader->pushNormalizer(function (array &$row) {
    $row = array_map('trim', $row);
});

// Add another sanitizer to convert a specific column to an integer
$reader->pushNormalizer(function (array &$row) {
    if (isset($row['age'])) {
        $row['age'] = (int) $row['age'];
    }
});
```

#### Filters

[](#filters)

Filters are used to validate and exclude entire rows. If a filter returns `false`, the line will be skipped and will not be yielded by the generator.

```
use Inwebo\Csv\Reader;

$reader = new Reader('path/to/your/file.csv');

// Add a filter to only include rows where the 'status' column is 'active'
$reader->pushFilter(function (array $row) {
    return isset($row['status']) && $row['status'] === 'active';
});

// Add another filter to only include users older than 25
$reader->pushFilter(function (array $row) {
    return isset($row['age']) && (int) $row['age'] > 25;
});
```

With both sanitizers and filters in place, the processing loop becomes a clean, declarative statement of what you want to achieve.

```
foreach ($reader->rows() as $row) {
    // This line has passed all your checks and is ready to be used
    print_r($row);
}
```

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance89

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

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

Total

4

Last Release

54d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/845359?v=4)[Inwebo Veritas](/maintainers/inwebo)[@inwebo](https://github.com/inwebo)

---

Top Contributors

[![inwebo](https://avatars.githubusercontent.com/u/845359?v=4)](https://github.com/inwebo "inwebo (7 commits)")

---

Tags

csvcsv-filescsv-parsercsv-readercsv-readingkissphpphpcsvreaderfiltersplsanitize

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[league/csv

CSV data manipulation made easy in PHP

3.5k166.1M646](/packages/league-csv)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.2k57.6M131](/packages/openspout-openspout)[csanquer/colibri-csv

Lightweight and performant CSV reader and writer library

16161.7k4](/packages/csanquer-colibri-csv)

PHPackages © 2026

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