Properties

$stream_filter_mode

$stream_filter_mode : integer

The stream filter mode (read or write).

Type

integer

$stream_filters

$stream_filters : array<mixed,boolean>

collection of stream filters.

Type

array<mixed,boolean>

$input_bom

$input_bom : string|null

The CSV document BOM sequence.

Type

string|null

$output_bom

$output_bom : string

The Output file BOM character.

Type

string

$delimiter

$delimiter : string

the field delimiter (one character only).

Type

string

$enclosure

$enclosure : string

the field enclosure character (one character only).

Type

string

$escape

$escape : string

the field escape character (one character only).

Type

string

$document

$document : \SplFileObject|\League\Csv\Stream

The CSV document.

Type

\SplFileObject|\League\Csv\Stream

$is_input_bom_included

$is_input_bom_included : boolean

Tells whether the Input BOM must be included or skipped.

Type

boolean

$header_offset

$header_offset : integer|null

header offset.

Type

integer|null

$header

$header : array<mixed,string>

header record.

Type

array<mixed,string>

$nb_records

$nb_records : integer

records count.

Type

integer

$is_empty_records_included

$is_empty_records_included : boolean

Type

boolean

Methods

__destruct()

__destruct() 

{@inheritdoc}

__clone()

__clone() 

{@inheritdoc}

createFromFileObject()

createFromFileObject(\SplFileObject  $file) : static

Return a new instance from a SplFileObject.

Parameters

\SplFileObject $file

Returns

static

createFromStream()

createFromStream(resource  $stream) : static

Return a new instance from a PHP resource stream.

Parameters

resource $stream

Returns

static

createFromString()

createFromString(\League\Csv\string  $content = '') : static

Return a new instance from a string.

Parameters

\League\Csv\string $content

Returns

static

createFromPath()

createFromPath(\League\Csv\string  $path, \League\Csv\string  $open_mode = 'r', resource|null  $context = null) : static

Return a new instance from a file path.

Parameters

\League\Csv\string $path
\League\Csv\string $open_mode
resource|null $context

the resource context

Returns

static

getDelimiter()

getDelimiter() 

Returns the current field delimiter.

getEnclosure()

getEnclosure() 

Returns the current field enclosure.

getPathname()

getPathname() 

Returns the pathname of the underlying document.

getEscape()

getEscape() 

Returns the current field escape character.

getOutputBOM()

getOutputBOM() 

Returns the BOM sequence in use on Output methods.

getInputBOM()

getInputBOM() 

Returns the BOM sequence of the given CSV.

getStreamFilterMode()

getStreamFilterMode() 

Returns the stream filter mode.

supportsStreamFilter()

supportsStreamFilter() 

Tells whether the stream filter capabilities can be used.

hasStreamFilter()

hasStreamFilter(\League\Csv\string  $filtername) 

Tell whether the specify stream filter is attach to the current stream.

Parameters

\League\Csv\string $filtername

isInputBOMIncluded()

isInputBOMIncluded() 

Tells whether the BOM can be stripped if presents.

chunk()

chunk(integer  $length) 

Retuns the CSV document as a Generator of string chunk.

Parameters

integer $length

number of bytes read

Throws

\League\Csv\Exception

if the number of bytes is lesser than 1

__toString()

__toString() 

DEPRECATION WARNING! This method will be removed in the next major point release.

getContent()

getContent() 

Retrieves the CSV content.

output()

output(\League\Csv\string  $filename = null) : integer

Outputs all data on the CSV file.

Parameters

\League\Csv\string $filename

Returns

integer —

Returns the number of characters read from the handle and passed through to the output.

setDelimiter()

setDelimiter(\League\Csv\string  $delimiter) : static

Sets the field delimiter.

Parameters

\League\Csv\string $delimiter

Throws

\League\Csv\Exception

If the Csv control character is not one character only.

Returns

static

setEnclosure()

setEnclosure(\League\Csv\string  $enclosure) : static

Sets the field enclosure.

Parameters

\League\Csv\string $enclosure

Throws

\League\Csv\Exception

If the Csv control character is not one character only.

Returns

static

setEscape()

setEscape(\League\Csv\string  $escape) : static

Sets the field escape character.

Parameters

\League\Csv\string $escape

Throws

\League\Csv\Exception

If the Csv control character is not one character only.

Returns

static

skipInputBOM()

skipInputBOM() : static

Enables BOM Stripping.

Returns

static

includeInputBOM()

includeInputBOM() : static

Disables skipping Input BOM.

Returns

static

setOutputBOM()

setOutputBOM(\League\Csv\string  $str) : static

Sets the BOM sequence to prepend the CSV on output.

Parameters

\League\Csv\string $str

Returns

static

addStreamFilter()

addStreamFilter(\League\Csv\string  $filtername, null|mixed  $params = null) : static

append a stream filter.

Parameters

\League\Csv\string $filtername
null|mixed $params

Throws

\League\Csv\Exception

If the stream filter API can not be used

Returns

static

getHeaderOffset()

getHeaderOffset() : integer|null

Returns the header offset.

If no CSV header offset is set this method MUST return null

Returns

integer|null

getHeader()

getHeader() : array<mixed,string>

Returns the CSV record used as header.

The returned header is represented as an array of string values

Returns

array<mixed,string>

__call()

__call(  $method, array  $arguments) 

{@inheritdoc}

Parameters

$method
array $arguments

count()

count() 

{@inheritdoc}

getIterator()

getIterator() 

{@inheritdoc}

jsonSerialize()

jsonSerialize() 

{@inheritdoc}

getRecords()

getRecords(array<mixed,string>  $header = array()) 

Returns the CSV records as an iterator object.

Each CSV record is represented as a simple array containing strings or null values.

If the CSV document has a header record then each record is combined to the header record and the header record is removed from the iterator.

If the CSV document is inconsistent. Missing record fields are filled with null values while extra record fields are strip from the returned object.

Parameters

array<mixed,string> $header

an optional header to use instead of the CSV document header

setHeaderOffset()

setHeaderOffset(integer|null  $offset) : static

Selects the record to be used as the CSV header.

Because the header is represented as an array, to be valid a header MUST contain only unique string value.

Parameters

integer|null $offset

the header record offset

Throws

\League\Csv\Exception

if the offset is a negative integer

Returns

static

skipEmptyRecords()

skipEmptyRecords() 

Enable skipping empty records.

includeEmptyRecords()

includeEmptyRecords() 

Disable skipping empty records.

isEmptyRecordsIncluded()

isEmptyRecordsIncluded() 

Tells whether empty records are skipped by the instance.

fetchOne()

fetchOne(integer  $nth_record) : array

Returns a single record from the CSV

Parameters

integer $nth_record

Returns

array

fetchColumn()

fetchColumn(string|integer  $column_index) : \Generator

Returns the next value from a single CSV record field

Parameters

string|integer $column_index

Returns

\Generator

fetchPairs()

fetchPairs(string|integer  $offset_index, string|integer  $value_index = 1) : \Generator

Fetches the next key-value pairs from the CSV document

Parameters

string|integer $offset_index
string|integer $value_index

Returns

\Generator

__construct()

__construct(\SplFileObject|\League\Csv\Stream  $document) 

New instance.

Parameters

\SplFileObject|\League\Csv\Stream $document

The CSV Object instance

resetProperties()

resetProperties() 

Reset dynamic object properties to improve performance.

sendHeaders()

sendHeaders(\League\Csv\string  $filename) 

Send the CSV headers.

Adapted from Symfony\Component\HttpFoundation\ResponseHeaderBag::makeDisposition

Parameters

\League\Csv\string $filename

Throws

\League\Csv\Exception

if the submitted header is invalid according to RFC 6266

setHeader()

setHeader(\League\Csv\int  $offset) : array<mixed,string>

Determine the CSV record header.

Parameters

\League\Csv\int $offset

Throws

\League\Csv\Exception

If the header offset is set and no record is found or is the empty array

Returns

array<mixed,string>

seekRow()

seekRow(\League\Csv\int  $offset) : array|false

Returns the row at a given offset.

Parameters

\League\Csv\int $offset

Returns

array|false

getDocument()

getDocument() 

Returns the document as an Iterator.

removeBOM()

removeBOM(array<mixed,string>  $record, \League\Csv\int  $bom_length, \League\Csv\string  $enclosure) : array<mixed,string>

Strip the BOM sequence from a record.

Parameters

array<mixed,string> $record
\League\Csv\int $bom_length
\League\Csv\string $enclosure

Returns

array<mixed,string>

computeHeader()

computeHeader(array<mixed,string>  $header) : array<mixed,string>

Returns the header to be used for iteration.

Parameters

array<mixed,string> $header

Throws

\League\Csv\Exception

If the header contains non unique column name

Returns

array<mixed,string>

combineHeader()

combineHeader(\Iterator  $iterator, array<mixed,string>  $header) 

Combine the CSV header to each record if present.

Parameters

\Iterator $iterator
array<mixed,string> $header

stripBOM()

stripBOM(\Iterator  $iterator, \League\Csv\string  $bom) 

Strip the BOM sequence from the returned records if necessary.

Parameters

\Iterator $iterator
\League\Csv\string $bom