CSV · Reading
CSV reading examples.
Package-local, copy-ready examples organized like the classes and methods reference. Open one example at a time, search by method, and jump from the right-side index.
CSV individual library
Reading examples with copy-ready, production-minded PHP.
Every snippet uses mnb/mnb-phpexcel-csv or its declared Core dependency. Each copied snippet includes strict typing, a concise summary, implementation guidance, readable limits, and a safe fixture check.
- 2
- examples
- 4
- documented methods
Csv::read()withHeaderRow()streaming()rows()<?php
declare(strict_types=1);
/*
Summary:
Stream a delimited file while detecting its source dialect and encoding.
Implementation note:
Automatic detection is convenient for uploads. Pin the dialect for known integrations to make
failures deterministic.
*/
use Mnb\PHPExcel\Format\Csv;
$rows = Csv::read(__DIR__ . '/inventory.csv', [
'delimiter' => 'auto',
'encoding' => 'auto',
'target_encoding' => 'UTF-8',
'trim_values' => true,
'empty_strings_to_null' => true,
'ignore_blank_lines' => true,
])->withHeaderRow(1)->streaming()->rows();Csv::read()withHeaderRow()rows()<?php
declare(strict_types=1);
/*
Summary:
Use the Excel-tab dialect, limit source rows, and retain only selected columns.
Implementation note:
CSV is one logical sheet. Source slicing and projection are the main tools for reducing work
before application processing.
*/
use Mnb\PHPExcel\Format\Csv;
$rows = Csv::read(__DIR__ . '/events.tsv', [
'dialect' => 'excel_tab',
'start_row' => 2,
'source_limit_rows' => 5_000,
'columns' => [1, 3, 7],
])->withHeaderRow(1)->rows();No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue