Documentation

Csv
in package

Represents data loaded from or stored in CSV format

Tags
copyright

Cloudrexx AG

author

Michael Ritter michael.ritter@cloudrexx.com

subpackage

lib_convert

Table of Contents

Properties

$enclosure  : string
$separator  : string

Methods

__construct()  : mixed
Constructor
parseFile()  : void
Returns the content of a csv file indexed by the first row containing data
startsWithUtf8Bom()  : bool
Check if string starts with UTF-8 BOM

Properties

Methods

__construct()

Constructor

public __construct([string $separator = ';' ][, string $enclosure = '"' ]) : mixed
Parameters
$separator : string = ';'

(optional) Separator character to use, defaults to ;

$enclosure : string = '"'

(optional) Enclosure character to use, defaults to "

parseFile()

Returns the content of a csv file indexed by the first row containing data

public parseFile(Cx $cx, File $file, callable $callback[, bool $columnNamesInFirstRow = true ][, int $limit = -1 ][, int $offset = -1 ]) : void

Please note that this method will attempt to write to the file if no UTF-8 BOM is detected.

If $limit and $offset are used:

  • If $columnNamesInFirstRow is true, the first row is always read
  • If $columnNamesInFirstRow is true, this row does not count towards the limit
  • Empty rows are skipped and do not count towards limit or offset

The $callback will be called for each non-empty row. It will receive the parsed CSV data (indexed by header rows if $columnNamesInFirstRow is true) and the number of the entry (nth non-empty entry).

Parameters
$cx : Cx
$file : File

File instance to read CSV from

$callback : callable

Will be called for each row if provided.

$columnNamesInFirstRow : bool = true

(optional) If set to false, the first row is treated as data

$limit : int = -1

(optional) Limit the number of rows returned.

$offset : int = -1

(optional) Offset as of which entry limit is counted.

Tags
throws
FileException

If the file could not be opened

startsWithUtf8Bom()

Check if string starts with UTF-8 BOM

protected startsWithUtf8Bom(mixed $fileHandle) : bool
Parameters
$fileHandle : mixed
Return values
bool

True of $string stars with the UTF-8 BOM


        
On this page

Search results