Documentation

Csv
in package
implements ImportInterface

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

Interfaces

ImportInterface
Imports data from a specific format into an array

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[, int $limit = -1 ][, int $offset = -1 ][, array<string|int, mixed> $options = array() ]) : 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 $options['columnNamesInFirstRow'] is true, the first row is always read
  • If $options['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.

$limit : int = -1

(optional) Limit the number of rows returned.

$offset : int = -1

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

$options : array<string|int, mixed> = array()

(optional) If the index columnNamesInFirstRow is set to false, the first column is treated as data

Tags
todo

Handling of encoding should be done outside of this.

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