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

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

yidas/csv
=========

PHP CSV writer &amp; reader with settings of quoting enclosure and encoding

1.0.0(4y ago)61.5k↓100%1MITPHP

Since Sep 6Pushed 4y ago1 watchersCompare

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

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

 [ ![](https://camo.githubusercontent.com/e331c9b89ef09fa1b8b98af2ae68dbd2e88d1dba522f0bf653292a94b3b28c37/68747470733a2f2f7777772e7068702e6e65742f696d616765732f6c6f676f732f7068702d6c6f676f2d6269676765722e706e67) ](https://codeigniter.com/)

PHP CSV
=======

[](#php-csv)

PHP CSV writer &amp; reader with settings of quoting enclosure and encoding

[![Latest Stable Version](https://camo.githubusercontent.com/568897269252c18f563903353fee8538113e692f59dabe3eef14a04b42e4f594/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f6373762f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/csv)[![License](https://camo.githubusercontent.com/e2350c3518046974410c50872b33f4727e74139bc321ceb73dec1f9cc50fb05c/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f6373762f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/csv)

Features
--------

[](#features)

- *Support generating **Double Quotes** enclosure for all entities setting*
- *Support **Encoding** setting for local dialect*
- ***Elegent Interface** for setup and use*

---

OUTLINE
-------

[](#outline)

- [Demonstration](#demonstration)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Options](#options)
    - [Writer](#writer)
    - [Reader](#reader)
    - [Exceptions](#exceptions)
- [References](#references)

---

DEMONSTRATION
-------------

[](#demonstration)

Quickstart with specifying the file name directly:

```
// Read the CSV file
$csvReader = new yidas\csv\Reader('/tmp/file.csv');
$rows = $csvReader->readRows();
$csvReader->fclose();
// Write the CSV file
$csvWriter = new yidas\csv\Writer('/tmp/file.csv');
$csvWriter->writeRows($rows);
$csvWriter->fclose();
```

### Write to CSV

[](#write-to-csv)

Open a file and use libray to write in CSV format:

```
$fp = fopen("/tmp/file.csv", 'w');

$csvWriter = new yidas\csv\Writer($fp, [
    // 'quoteAll' => true,
    // 'encoding' => 'UTF-8'
]);
$csvWriter->writeRow(["First", 'Second']);
$csvWriter->writeRows([
    ["Normal", 'Double"Quote'],
    ["It's a context,\nNew line.", 'Encoded中文'],
]);

fclose($fp);
```

The content of generated CSV file will be:

```
"First","Second"
"Normal","Double""Quote"
"It's a context,
New line.","Encoded中文"
```

> In default setting, it will always add double quotes with `UTF-8` encoding.

### Read from CSV

[](#read-from-csv)

Open a CSV file with local encoding (`Big5`) and use libray to read with `UTF-8` encoding:

```
$fp = fopen("/tmp/file.csv", 'r');

$csvReader = new yidas\csv\Reader($fp, [
    'encoding' => 'Big5'
]);
$firstRow = $csvReader->readRow();
$remainingRows = $csvReader->readRows();

fclose($fp);
```

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- PHP CLI 5.4.0+

---

INSTALLATION
------------

[](#installation)

Run Composer in your project:

```
composer require yidas/csv

```

Then you could use the class after Composer is loaded on your PHP project:

```
require __DIR__ . '/vendor/autoload.php';

use yidas\csv\Writer;
use yidas\csv\Reader;
```

---

USAGE
-----

[](#usage)

### Options

[](#options)

The options in parameter 2 for Writer/Reader class are as below:

#### quoteAll

[](#quoteall)

Controls when quotes should be always generated by the writer.

#### Encoding

[](#encoding)

Controls which the encoding should be generated by the writer/reader.

> By defaule, Microsoft Excel will open CSV file with local encoding. For example: Excel in Chinese(Traditional) Windows will open CSV with Big5 encoding.

### Writer

[](#writer)

```
$csvWriter = new yidas\csv\Writer($fp, [
    // 'quoteAll' => true,
    // 'encoding' => 'UTF-8'
]);
```

#### writeRow()

[](#writerow)

Write the row parameter to the writer’s file stream, formatted according to the current setting.

```
public static array writeRow(array $rowData)
```

#### writeRows()

[](#writerows)

Write the rows parameter to the writer’s file stream, formatted according to the current setting.

```
public static array writeRows(array $rowsData)
```

### Reader

[](#reader)

```
$csvReader = new yidas\csv\Reader($fp, [
    // 'encoding' => 'UTF-8'
]);
```

#### readRow()

[](#readrow)

Read a row from current file pointer.

```
public static array readRow()
```

*Example:*

```
while ( ($row = $csvReader->readRow($file) ) !== FALSE ) {
    var_dump($row);
}
```

#### readRows()

[](#readrows)

Read all the rows from current file pointer.

```
public static array readRows()
```

*Example:*

```
$rows = $csvReader->readRows();
var_dump($rows);
```

### Exceptions

[](#exceptions)

```
try {

    $csvWriter = new yidas\csv\Writer($fp, [
        // 'quoteAll' => true,
        // 'encoding' => 'UTF-8'
    ]);
    $csvWriter->writeRow(["First", 'Second']);

} catch (\Exception $e) {

    echo 'Code:' . $e->getCode() . ' Message:' . $e->getMessage();
}
```

---

REFERENCES
----------

[](#references)

- [Comma-separated values - Basic rules - Wiki](https://en.wikipedia.org/wiki/Comma-separated_values#Basic_rules)
- [RFC 4180 - Common Format and MIME Type for Comma-Separated Values (CSV) Files](https://datatracker.ietf.org/doc/html/rfc4180)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

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

Unknown

Total

1

Last Release

1706d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b30d2b2c0b53aef65fad4af56cd3c7912d3db2b612890c706fe79448717f6aba?d=identicon)[yidas](/maintainers/yidas)

---

Top Contributors

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

---

Tags

csvcsv-readercsv-writerdouble-quotesencodingphpphpcsvcsv writercsv readerExcel CSVQuoting CSV

### Embed Badge

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

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

###  Alternatives

[openspout/openspout

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

1.1k57.6M128](/packages/openspout-openspout)[tonirilix/nested-json-flattener

A php package to flatten nested json objects and nested arrays. It also allows you to create csv files from the flattened data.

28107.6k](/packages/tonirilix-nested-json-flattener)

PHPackages © 2026

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