CrmCsv
in package
Read and write CSV files
Tags
Table of Contents
Properties
- $mFldEscape : string
- Escape character
- $mFldQuote : string
- Quote character
- $mFldSeparator : string
- Separator character
- $mHandle : resource
- Holds the file handle
- $mRowCount : int
- Counts the number of rows that have been returned
- $mRowSize : int
- Length of the largest row in bytes
- $mSkipEmptyRows : bool
- Determines whether empty rows should be skipped.
- $mSkippedRowCount : int
- Counts the number of empty rows that have been skipped
- $mTrimFields : bool
- Specifies whether the fields leading and trailing \s and \t should be removed.
Methods
- __construct() : mixed
- Constructor
- ArrayRemoveEscape() : mixed
- Escape the quote character
- ArrayTrim() : mixed
- Strip leading and trailing whitespace from the elements of an array
- Csv2Array() : mixed
- csv::Csv2Array will return the whole csv file as 2D array
- NextLine() : array<string|int, mixed>
- csv::NextLine() returns an array of fields from the next csv line.
- RowCount() : int
- csv::RowCount return the current row count
- SkipEmptyRows() : void
- csv::SkipEmptyRows, sets whether empty rows should be skipped or not
- SkippedRowCount() : int
- csv::RowCount return the current skipped row count
- TrimFields() : void
- csv::TrimFields, sets whether fields should have their \s and \t removed.
- write() : array<string|int, mixed>
- Writes the array to the CSV file
Properties
$mFldEscape
Escape character
private
string
$mFldEscape
= '\\'
Tags
$mFldQuote
Quote character
private
string
$mFldQuote
= '"'
Tags
$mFldSeparator
Separator character
private
string
$mFldSeparator
= ';'
Tags
$mHandle
Holds the file handle
private
resource
$mHandle
= null
Tags
$mRowCount
Counts the number of rows that have been returned
private
int
$mRowCount
= 0
Tags
$mRowSize
Length of the largest row in bytes
private
int
$mRowSize
= 4096
Tags
$mSkipEmptyRows
Determines whether empty rows should be skipped.
private
bool
$mSkipEmptyRows
= false
By default empty rows are NOT skipped.
Tags
$mSkippedRowCount
Counts the number of empty rows that have been skipped
private
int
$mSkippedRowCount
= 0
Tags
$mTrimFields
Specifies whether the fields leading and trailing \s and \t should be removed.
private
bool
$mTrimFields
= true
Defaults to true.
Tags
Methods
__construct()
Constructor
public
__construct([str $file = '' ][, str $separator = ';' ][, str $quote = '"' ][, str $escape = '\' ]) : mixed
Only initialises class settings variables.
Parameters
- $file : str = ''
-
- file path
- $separator : str = ';'
-
- Only one character is allowed (optional)
- $quote : str = '"'
-
- Only one character is allowed (optional)
- $escape : str = '\'
-
- Only one character is allowed (optional)
Tags
ArrayRemoveEscape()
Escape the quote character
public
ArrayRemoveEscape(Address &$item) : mixed
Called by array_walk()
Parameters
- $item : Address
Tags
ArrayTrim()
Strip leading and trailing whitespace from the elements of an array
public
ArrayTrim(Address &$item) : mixed
Called by array_walk(). Spaces and tabs are removed (\s and \t).
Parameters
- $item : Address
Tags
Csv2Array()
csv::Csv2Array will return the whole csv file as 2D array
public
Csv2Array() : mixed
Tags
NextLine()
csv::NextLine() returns an array of fields from the next csv line.
public
NextLine() : array<string|int, mixed>
The position of the file pointer is stored in PHP internals. Empty rows can be skipped. Leading and trailing \s and \t can be removed from each field.
Tags
Return values
array<string|int, mixed> —of fields
RowCount()
csv::RowCount return the current row count
public
RowCount() : int
Tags
Return values
intSkipEmptyRows()
csv::SkipEmptyRows, sets whether empty rows should be skipped or not
public
SkipEmptyRows([bool $bool = true ]) : void
Parameters
- $bool : bool = true
Tags
SkippedRowCount()
csv::RowCount return the current skipped row count
public
SkippedRowCount() : int
Tags
Return values
intTrimFields()
csv::TrimFields, sets whether fields should have their \s and \t removed.
public
TrimFields([bool $bool = true ]) : void
Parameters
- $bool : bool = true
Tags
write()
Writes the array to the CSV file
public
write(string $filename, array<string|int, mixed> $arrCsv) : array<string|int, mixed>
Parameters
- $filename : string
- $arrCsv : array<string|int, mixed>
Tags
Return values
array<string|int, mixed> —of fields