‪TYPO3CMS  ‪main
TYPO3\CMS\Core\Utility\CsvUtility Class Reference

Static Public Member Functions

static csvToArray (string $input, string $fieldDelimiter=',', string $fieldEnclosure='"', int $maximumColumns = 0)
static string csvValues (array $row, string $delim=',', string $quote='"', int $type = self::TYPE_REMOVE_CONTROLS)

Public Attributes


Static Protected Member Functions

static prefixControlLiterals (bool|int|float|string|null $cellValue)
static removeControlLiterals (bool|int|float|string|null $cellValue)
static assertCellValueType (mixed $cellValue)
static shallFilterValue (bool|int|float|string|null $cellValue)

Detailed Description

Class with helper functions for CSV handling

Definition at line 25 of file CsvUtility.php.

Member Function Documentation

◆ assertCellValueType()

static TYPO3\CMS\Core\Utility\CsvUtility::assertCellValueType ( mixed  $cellValue)

Asserts scalar or null types for given cell value.

Definition at line 149 of file CsvUtility.php.

◆ csvToArray()

static TYPO3\CMS\Core\Utility\CsvUtility::csvToArray ( string  $input,
string  $fieldDelimiter = ',',
string  $fieldEnclosure = '"',
int  $maximumColumns = 0 

Convert a string, formatted as CSV, into a multidimensional array

This cannot be done by str_getcsv, since it's impossible to handle enclosed cells with a line feed in it

string$input‪The CSV input
string$fieldDelimiter‪The field delimiter
string$fieldEnclosure‪The field enclosure
int$maximumColumns‪The maximum amount of columns

Definition at line 53 of file CsvUtility.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\CsvUtilityTest\csvToArraySplitsAsExpected(), and TYPO3\CMS\Frontend\DataProcessing\CommaSeparatedValueProcessor\process().

◆ csvValues()

static string TYPO3\CMS\Core\Utility\CsvUtility::csvValues ( array  $row,
string  $delim = ',',
string  $quote = '"',
int  $type = self::TYPE_REMOVE_CONTROLS 

Takes a row and returns a CSV string of the values with $delim (default is ,) and $quote (default is ") as separator chars.

string[]$row‪Input array of values
string$delim‪Delimited, default is comma
string$quote‪Quote-character to wrap around the values.
int$type‪Output behaviour concerning potentially harmful control literals
‪string A single line of CSV

Definition at line 100 of file CsvUtility.php.

References TYPO3\CMS\Core\IO\CsvStreamFilter\applyStreamFilter().

Referenced by TYPO3\CMS\Lowlevel\Controller\DatabaseIntegrityController\csvValues(), and TYPO3\CMS\Core\Tests\Unit\Utility\CsvUtilityTest\csvValuesReturnsExpectedResult().

◆ prefixControlLiterals()

static TYPO3\CMS\Core\Utility\CsvUtility::prefixControlLiterals ( bool|int|float|string|null  $cellValue)

Prefixes control literals at the beginning of a cell value with a single quote

(e.g. =+value --> ‘’=+value`)

Definition at line 123 of file CsvUtility.php.

◆ removeControlLiterals()

static TYPO3\CMS\Core\Utility\CsvUtility::removeControlLiterals ( bool|int|float|string|null  $cellValue)

Removes control literals from the beginning of a cell value

(e.g. =+value --> value)

Definition at line 137 of file CsvUtility.php.

◆ shallFilterValue()

static TYPO3\CMS\Core\Utility\CsvUtility::shallFilterValue ( bool|int|float|string|null  $cellValue)

Whether cell value shall be filtered.

This applies to everything that is not or cannot be represented as boolean, integer or float.

Definition at line 167 of file CsvUtility.php.

Member Data Documentation


const TYPO3\CMS\Core\Utility\CsvUtility::TYPE_PASSTHROUGH = 0

whether to passthrough data as is, without any modification

Definition at line 30 of file CsvUtility.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\CsvUtilityTest\csvValuesDataProvider().


const TYPO3\CMS\Core\Utility\CsvUtility::TYPE_PREFIX_CONTROLS = 2

whether to prefix control characters like =, +, ... to become ‘’=,'+`, ...

Definition at line 41 of file CsvUtility.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\CsvUtilityTest\csvValuesDataProvider().


const TYPO3\CMS\Core\Utility\CsvUtility::TYPE_REMOVE_CONTROLS = 1

whether to remove control characters like =, +, ...

Definition at line 35 of file CsvUtility.php.

Referenced by TYPO3\CMS\Core\Tests\Unit\Utility\CsvUtilityTest\csvValuesDataProvider().