MNB PHPExcelDeveloper Guide

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.

Packagemnb/mnb-phpexcel-csv:^2.0Reference2 examples · 4 methods
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
Example 01

Detect CSV delimiter and encoding

Open related guide
Csv::read()withHeaderRow()streaming()rows()
detect-csv-delimiter-and-encoding.php
<?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();