CsvStreamFilter extends php_user_filter

Inspired by https://csv.thephpleague.com/9.0/interoperability/enclose-field/

A unique sequence is added to relevant CSV field values in order to trigger enclosure in fputcsv. This stream filter is taking care of removing that sequence again when actually writing to stream.

Table of Contents

Constants

NAME  = 'csv.typo3'

Methods

applyStreamFilter()  : Closure
filter()  : int
Implicitly handles stream filter when writing CSV data - example:
buildStreamFilterModifier()  : Closure
registerStreamFilter()  : mixed
Registers stream filter

Constants

Methods

applyStreamFilter()

public static applyStreamFilter(resource $stream[, bool $LF = true ]) : Closure
Parameters
$stream : resource
$LF : bool = true

whether to apply line-feed

Return values
Closure

filter()

Implicitly handles stream filter when writing CSV data - example:

public filter(resource $in, resource $out, int &$consumed, bool $closing) : int
Parameters
$in : resource
$out : resource
$consumed : int
$closing : bool
Tags
example
$resource = fopen('file.csv', 'w');
$modifier = CsvUtility::applyStreamFilter($resource);
fputcsv($resource, $modifier($fieldValues));
fclose($resource);
Return values
int

buildStreamFilterModifier()

protected static buildStreamFilterModifier(string $sequence) : Closure
Parameters
$sequence : string
Return values
Closure

registerStreamFilter()

Registers stream filter

protected static registerStreamFilter() : mixed

        
On this page

Search results