PHPackages                             belguinan/csv-simple-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. belguinan/csv-simple-reader

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

belguinan/csv-simple-reader
===========================

A lightweight, zero-dependency PHP library for reading, writing, and exporting CSV files. Works with PHP 5.4 and above.

v1.1.3(1y ago)0695MITPHPPHP &gt;=5.4.0

Since Jan 22Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (4)Used By (0)

CSV Simple Reader
=================

[](#csv-simple-reader)

A lightweight, zero-dependency PHP library for reading, writing, and exporting CSV files. Works with PHP 5.4 and above.

[![License: MIT](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Features
--------

[](#features)

- 🚀 Simple and intuitive API
- 📖 Memory-efficient reading of large files
- 💾 Export data to CSV files
- ⬇️ Direct CSV downloads
- 🔒 Secure file handling
- 0️⃣ Zero dependencies
- ✅ PHP 5.4+ compatible

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

[](#installation)

Install via Composer:

```
composer require belguinan/csv-simple-reader
```

Quick Start
-----------

[](#quick-start)

```
use Belguinan\CsvExporter;

// Initialize
$csv = new CsvExporter();

// Read CSV file
foreach ($csv->readFrom('path/to/file.csv') as $row) {
    var_dump($row);
}
```

Usage Guide
-----------

[](#usage-guide)

### Reading CSV Files

[](#reading-csv-files)

```
$csv = new CsvExporter();

// Read file line by line (memory efficient)
foreach ($csv->readFrom('input.csv') as $row) {
    // $row is an array containing the CSV columns
    var_dump($row);
}
```

### Creating CSV Files

[](#creating-csv-files)

```
// Your data as array
$data = array(
    array('John', 'Doe', 'john@example.com'),
    array('Jane', 'Smith', 'jane@example.com')
);

// Optional headers
$headers = array('First Name', 'Last Name', 'Email');

// Create CSV exporter
$csv = new CsvExporter($data, $headers);

// Process and save
$csv->process()->save('output.csv');
```

### Downloading CSV Files

[](#downloading-csv-files)

```
// Create and force download
$csv = new CsvExporter($data, $headers);
$csv->process()->download('users-export');
```

### Chaining Operations

[](#chaining-operations)

```
// Process, download, and save in one go
$csv->process()
    ->download('export-file')
    ->save('backup/export.csv');
```

Error Handling
--------------

[](#error-handling)

The library throws `Exception` for various error conditions. It's recommended to wrap operations in try-catch blocks:

```
try {
    $csv = new CsvExporter($data);
    $csv->process()->save('output.csv');
} catch (\Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

Common Exceptions
-----------------

[](#common-exceptions)

- File not found
- File not readable
- Directory not writable
- Invalid CSV data structure
- Memory stream errors

Best Practices
--------------

[](#best-practices)

1. **Reading Large Files**

    ```
    // Good - Memory efficient
    foreach ($csv->readFrom('large.csv') as $row) {
        processRow($row);
    }
    ```
2. **Setting Headers**

    ```
    // Explicit headers
    $headers = array('ID', 'Name', 'Email');
    $csv = new CsvExporter($data, $headers);

    // Auto-generated headers from data keys
    $csv = new CsvExporter($data);
    ```
3. **Error Handling**

    ```
    try {
        $csv->readFrom('file.csv');
    } catch (\Exception $e) {
        log_error($e->getMessage());
        // Handle error appropriately
    }
    ```

Examples
--------

[](#examples)

### Export Users Table

[](#export-users-table)

```
// Fetch users from database
$users = $db->query('SELECT id, name, email FROM users');

// Convert to array
$data = array();
while ($row = $users->fetch_assoc()) {
    $data[] = $row;
}

// Export
$csv = new CsvExporter($data);
$csv->process()->download('users-export');
```

### Process CSV in Chunks

[](#process-csv-in-chunks)

```
$csv = new CsvExporter();
$chunk = array();

foreach ($csv->readFrom('large-file.csv') as $index => $row) {
    $chunk[] = $row;

    // Process in chunks of 1000
    if (count($chunk) >= 1000) {
        processChunk($chunk);
        $chunk = array();
    }
}

// Process remaining rows
if (!empty($chunk)) {
    processChunk($chunk);
}
```

License
-------

[](#license)

MIT License - feel free to use this library in your projects.

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

Support
-------

[](#support)

For bugs and feature requests, please use the [GitHub issue tracker](https://github.com/belguinan/csv-simple-reader/issues).

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity13

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

Total

3

Last Release

558d ago

Major Versions

0.1 → v1.1.22024-10-29

### Community

Maintainers

![](https://www.gravatar.com/avatar/021e78d0e1c9b1af3a87a6e04e5d533781af1adeca49d28624915dd6c26a8ebd?d=identicon)[belguinan](/maintainers/belguinan)

---

Top Contributors

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

---

Tags

csvcsv-exportcsv-importcsv-readerphpphp5exportcsvwriterreaderimportcsv-exportcsv writercsv readerphp-csv

### Embed Badge

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

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

###  Alternatives

[maatwebsite/excel

Supercharged Excel exports and imports in Laravel

12.7k144.3M711](/packages/maatwebsite-excel)[league/csv

CSV data manipulation made easy in PHP

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

CSV import/export library

9555.6M23](/packages/goodby-csv)[csanquer/colibri-csv

Lightweight and performant CSV reader and writer library

16161.7k4](/packages/csanquer-colibri-csv)[handcraftedinthealps/goodby-csv

CSV import/export library

441.6M4](/packages/handcraftedinthealps-goodby-csv)[ufirst/lang-import-export

A Laravel package providing artisan commands to import and export language files from and to CSV.

42207.9k](/packages/ufirst-lang-import-export)

PHPackages © 2026

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