CSV Module
Stream CSV and TSV data with dialect presets, delimiter detection, encoding conversion, projection, and safe output.
Updated
Csv::read()Csv::write()CsvDialect::detectDelimiter()EncodingDetector::detectFile()What you will learn
- Install the single-sheet text format module.
- Read large delimited files row by row.
- Write Excel-friendly output while preventing formula injection.
Install the CSV package#
composer require mnb/mnb-phpexcel:^2.0Understand the format model#
| Characteristic | CSV behavior |
|---|---|
| Worksheets | One logical sheet named Sheet1. |
| Types | Text fields; applications decide numeric, date, and boolean conversion. |
| Streaming | Forward-only fgetcsv() row iteration. |
| Dialect | Excel, Excel-tab, semicolon, Unix, pipe, or custom controls. |
| Encoding | Automatic detection and conversion to a requested target encoding. |
Start with focused read and write APIs#
use Mnb\PHPExcel\Format\Csv;
$rows = Csv::read('customers.csv', [
'delimiter' => 'auto',
'encoding' => 'auto',
'trim_values' => true,
])->withHeaderRow(1)->rows();use Mnb\PHPExcel\Format\Csv;
Csv::write($customers, 'customers.csv', [
'with_header' => true,
'dialect' => 'excel',
'encoding' => 'UTF-8',
'csv_injection_policy' => 'escape',
]);Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue