PHPackages                             jeroenzwart/php-csv-iterator - 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. jeroenzwart/php-csv-iterator

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

jeroenzwart/php-csv-iterator
============================

A simple CSV reader, to read as array/object with PHP Iterator

v1.0.3(5y ago)1982GPL-3.0-or-laterPHPPHP &gt;=7.3.0CI failing

Since Apr 28Pushed 5y ago1 watchersCompare

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

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

PHP CSV Iterator
================

[](#php-csv-iterator)

> #### A simple CSV reader with PHP Iterator
>
> [](#a-simple-csv-reader-with-php-iterator)

[![PHP from Packagist](https://camo.githubusercontent.com/73fbc2f0c48ba14883035974d45a6d3f7125b0fceb5e63fa8d98e350c8f7144e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/73fbc2f0c48ba14883035974d45a6d3f7125b0fceb5e63fa8d98e350c8f7144e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)[![GitHub code size in bytes](https://camo.githubusercontent.com/314fc2647bd5e3bc3ee5bcfb7a1e4ed7c258ed8d2cd2cb651717078a299ccec5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/314fc2647bd5e3bc3ee5bcfb7a1e4ed7c258ed8d2cd2cb651717078a299ccec5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)[![GitHub release (latest SemVer)](https://camo.githubusercontent.com/f3235c2f1685d88fcda2f9dc05b61adc03e26782d7ed3a2a2f89b9a9ec22462a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f3235c2f1685d88fcda2f9dc05b61adc03e26782d7ed3a2a2f89b9a9ec22462a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)[![Scrutinizer build (GitHub/Bitbucket)](https://camo.githubusercontent.com/5ccc5d70332c4526ce47f00b3d1096ac518fc5fd4d1bda3299e3d7e60afb958b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/5ccc5d70332c4526ce47f00b3d1096ac518fc5fd4d1bda3299e3d7e60afb958b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)[![Scrutinizer coverage (GitHub/BitBucket)](https://camo.githubusercontent.com/8a48ccafdf9cd9b4649c90f61ffe11069571adfc9720d6a184d25ad0535dd670/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8a48ccafdf9cd9b4649c90f61ffe11069571adfc9720d6a184d25ad0535dd670/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)[![Scrutinizer code quality (GitHub/Bitbucket)](https://camo.githubusercontent.com/1f3b7279749d0398b7587af4b75e2b1c766658c0a92bff4ba6a1be4db2041701/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/1f3b7279749d0398b7587af4b75e2b1c766658c0a92bff4ba6a1be4db2041701/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f6a65726f656e7a776172742f7068702d6373762d6974657261746f723f7374796c653d666c61742d737175617265)

This package is an easy way to read CSV files. The CSV Reader will iterate over a CSV file with low memory usage.

### Features

[](#features)

- Returns an array with keys from the headers.
- Reads a specific line in the CSV file.
- Skip the empty lines.
- Reading a CSV file with an offset and/or limit.

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

[](#installation)

Via Composer

```
$ composer require jeroenzwart/php-csv-iterator
```

Usage
-----

[](#usage)

This example is a part of the CSV file *./csv/movies.csv*;

```
    name,year_release,order,imdb_rating
    Star Wars Episode I – The Phantom Menace,1999,1,6.5
    Star Wars Episode II – Attack of the Clones,2002,2,6.5

```

To loop over each item in the CSV file, you will use the reader like this;

```
$csv = new \JeroenZwart\CsvIterator\CsvReader('../csv/movies.csv');
$csv->delimiter('"')
foreach ($csv as $line) {
    var_dump($line)
    // Or do something with $line...
}
// The first dump will look like this
// class stdClass(4) {
//     public 'name' => string(42) "Star Wars Episode I – The Phantom Menace"
//     public 'year_release' => string(4) "1999"
//     public 'order' => string(1) "1"
//     public 'imdb_rating' => string(3) "6.5"
// }
```

Or use one of the default iterator methods;

```
$csv = new \JeroenZwart\CsvIterator\CsvReader('../csv/movies.csv');
$line = $csv->next()->current();
```

Options
-------

[](#options)

- `filePath` *(string*) - Path to the CSV file.
- `offset` *(integer 0)* - The offset from start reading the CSV file.
- `limit` *(integer -1)* - The limit to end reading the CSV file.
- `delimiter` *(string ,)* - The delimiter character in the CSV file.
- `enclosure` *(string ")* - The enclosure character in the CSV file.
- `escape` *(string \\)* - The escape character in the CSV file.
- `hasHeaders` *(boolean TRUE)* - To set if the CSV file has a header, set FALSE if not.
- `asObject` *(boolean TRUE)* - Return the lines of the CSV file as object, set FALSE as array.
- `keepEmptyLines` *(boolean FALSE)* - Set TRUE for keeping an empty lines in the CSV file.

Examples
--------

[](#examples)

#### Offset and limit

[](#offset-and-limit)

Start reading with another position with offset and limit;

```
$csv = new CsvReader('../csv/actors.csv', 3, 5);
foreach ($csv as $line) {
    // Do something with $line...
}
```

#### Delimiter, enclose and escape

[](#delimiter-enclose-and-escape)

Read with another delimiter, enclose and escape;

```
$csv = new CsvReader('../csv/actors.csv');
$csv->delimiter(';')->enclose('`')->escape('');
foreach ($csv as $line) {
    // Do something with $line...
}
```

To get the current delimiter, enclosure or escape, you use `$csv->delimiter()`

#### Headers, asObject and empty

[](#headers-asobject-and-empty)

Ignore the headers in the CSV file and return array with regular keys, but keep empty lines;

```
$csv = new CsvReader('../csv/actors.csv');
$csv->headers(false)->asObject(false)->empty(true);
foreach ($csv as $line) {
    // Do something with $line...
}
```

To get the headers of a CSV file as array, you use `$csv->headers()`. For getting the modes for settings asObject or empty, you can use `$csv->asObject()` or `$csv->empty()`.

#### Position

[](#position)

Load a line at a given position;

```
$csv = new CsvReader('../csv/actors.csv');
var_dump($csv->position(3));
```

To get the current position of the iterator, you use `$csv->position()`

Change log
----------

[](#change-log)

Please see the [changelog](changelog.md) for more information on what has changed recently.

License
-------

[](#license)

Please see the [license file](LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community7

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

Total

4

Last Release

2181d ago

PHP version history (2 changes)v1.0PHP &gt;=7.3

v1.0.1PHP &gt;=7.3.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9d90d8bea93072e782a109825c5b7e32e73fd9a9fd48251c4033ca464065dc3d?d=identicon)[jeroenzwart](/maintainers/jeroenzwart)

---

Top Contributors

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

---

Tags

phpcsvreaderiteratorimportopenread

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/jeroenzwart-php-csv-iterator/health.svg)

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

###  Alternatives

[openspout/openspout

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

1.1k57.6M131](/packages/openspout-openspout)[shuchkin/simplecsv

Parse and retrieve data from CSV files. Export data to CSV.

5192.4k](/packages/shuchkin-simplecsv)

PHPackages © 2026

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