The League of Extraordinary Packages

Our Packages:

Presented by The League of Extraordinary Packages

Getting Started

Connections Settings

Inserting Records

Selecting Records


Converting Records

Upgrading Guide

This is the documentation for the upcoming version 9.0. This is a work in progress

Document loading

Because CSV documents come in different forms we use named constructors to offer several ways to load them.

Loading from a string


public static AbstractCsv::createFromString(string $str): self

Creates a new object from a given string.


use League\Csv\Reader;
use League\Csv\Writer;

$reader = Reader::createFromString('john,doe,');
$writer = Writer::createFromString('john,doe,');

Loading from a file path


public static AbstractCsv::createFromPath(
	string $path,
	string $open_mode = 'r+',
	resource $context = null
): self

Creates a new object à la fopen.


use League\Csv\Reader;
use League\Csv\Writer;

$reader = Reader::createFromPath('/path/to/your/csv/file.csv');
$writer = Writer::createFromPath('/path/to/your/csv/file.csv', 'w');

The $open_mode default to r+ if none is supplied.

Loading from a resource stream


public static AbstractCsv::createFromStream(resource $stream): self

Creates a new object from a stream resource.


use League\Csv\Reader;
use League\Csv\Writer;

$reader = Reader::createFromStream(fopen('/path/to/the/file.csv', 'r+'));
$writer = Writer::createFromStream(tmpfile());

The resource stream MUST be seekable otherwise an League\Csv\Exception exception is thrown.

Loading from a SplFileObject object


public static AbstractCsv::createFromFileObject(SplFileObject $obj): self

Creates a new object from a SplFileObject object.


use League\Csv\Reader;
use League\Csv\Writer;

$reader = Reader::createFromFileObject(new SplFileObject('/path/to/your/csv/file.csv'));
$writer = Writer::createFromFileObject(new SplTempFileObject());

The SplFileObject MUST be seekable otherwise a RuntimeException exception may be thrown.