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

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

alanvdb/csv
===========

A CSV stream handler implementing PSR-7 StreamInterface

v0.2(1y ago)04MITPHP

Since Mar 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Alanvdb/csv)[ Packagist](https://packagist.org/packages/alanvdb/csv)[ RSS](/packages/alanvdb-csv/feed)WikiDiscussions master Synced today

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

CsvReader Class
===============

[](#csvreader-class)

A simple and efficient PHP class for reading CSV files. This class implements the `ArrayAccess` and `Iterator` interfaces to provide a flexible way to interact with CSV data.

Features
--------

[](#features)

- Reads CSV files with a customizable delimiter (default is a comma).
- Supports CSV files with or without a header row.
- Provides access to CSV rows as arrays or associative arrays (if a header is provided).
- Implements `ArrayAccess` for easy array-like access to CSV rows.
- Implements `Iterator` for easy iteration over CSV rows.
- Read-only access to CSV data (modifying the data is not allowed).

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

[](#installation)

Simply download the `CsvReader.php` file and include it in your project. Alternatively, you can install it via Composer.

Usage
-----

[](#usage)

### Example 1: Simple CSV with Header

[](#example-1-simple-csv-with-header)

```
use AlanVdb\Csv\CsvReader;

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

foreach ($csv as $row) {
    echo $row['ColumnName']; // Access columns by header name if available
}
```

### Example 2: Simple CSV without Header

[](#example-2-simple-csv-without-header)

```
use AlanVdb\Csv\CsvReader;

$csv = new CsvReader('path/to/your/file.csv', ',', false);

foreach ($csv as $row) {
    print_r($row); // Access each row as a simple indexed array
}
```

### Example 3: Accessing Data via ArrayAccess

[](#example-3-accessing-data-via-arrayaccess)

```
use AlanVdb\Csv\CsvReader;

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

foreach ($csv as $row) {
    echo $row[0]; // Access the first column of the row
}
```

Methods
-------

[](#methods)

### `__construct(string $filePath, string $delimiter = ',', bool $hasHeader = true)`

[](#__constructstring-filepath-string-delimiter---bool-hasheader--true)

- `filePath` (string): Path to the CSV file.
- `delimiter` (string): The delimiter used in the CSV file (default is `,`).
- `hasHeader` (bool): Whether the CSV file has a header row (default is `true`).

Throws `RuntimeException` if the file cannot be read and `InvalidArgumentException` if the delimiter is empty.

### `current() : mixed`

[](#current--mixed)

Returns the current row of the CSV as an associative array (if the file has a header) or a simple indexed array.

### `key() : int`

[](#key--int)

Returns the current row's position (index) in the CSV.

### `next() : void`

[](#next--void)

Moves the pointer to the next row in the CSV file.

### `rewind() : void`

[](#rewind--void)

Rewinds the file pointer to the beginning of the CSV file and prepares the reader to start from the first row.

### `valid() : bool`

[](#valid--bool)

Checks if the current row is valid (i.e., not the end of the file).

### `offsetExists(mixed $offset) : bool`

[](#offsetexistsmixed-offset--bool)

Checks if a column (offset) exists in the current row.

### `offsetGet(mixed $offset) : mixed`

[](#offsetgetmixed-offset--mixed)

Gets the value of a specific column in the current row.

### `offsetSet(mixed $offset, mixed $value) : void`

[](#offsetsetmixed-offset-mixed-value--void)

Throws a `RuntimeException` since the CSV data is read-only.

### `offsetUnset(mixed $offset) : void`

[](#offsetunsetmixed-offset--void)

Throws a `RuntimeException` since the CSV data is read-only.

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

[](#requirements)

- PHP 7.4 or higher.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance42

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity29

Early-stage or recently created project

 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

2

Last Release

482d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/35227520?v=4)[Alan Van Den Bosch](/maintainers/alanvdb)[@Alanvdb](https://github.com/Alanvdb)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k656.1k38](/packages/neuron-core-neuron-ai)[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

346132.9M112](/packages/google-cloud-core)[spatie/laravel-export

Create a static site bundle from a Laravel app

674146.0k6](/packages/spatie-laravel-export)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[anthropic-ai/sdk

Anthropic PHP SDK

163583.3k16](/packages/anthropic-ai-sdk)

PHPackages © 2026

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