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 1mo ago

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

22

—

LowBetter than 22% of packages

Maintenance44

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

437d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79d5351bc1e25eb96224d5dd1bb67f5a60578d968784acf5f2c1edb897247b38?d=identicon)[alanvdb](/maintainers/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

[google/cloud-core

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

343121.4M79](/packages/google-cloud-core)[aimeos/aimeos-base

Aimeos base layer for abstracting from host environments

2.1k134.0k1](/packages/aimeos-aimeos-base)[phpgt/dom

Modern DOM API.

12412.2M18](/packages/phpgt-dom)[anthropic-ai/sdk

Anthropic PHP SDK

129134.7k5](/packages/anthropic-ai-sdk)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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