Property | Type | Description | |
---|---|---|---|
$_file | SplFileObject | Holds the CSV file pointer. | |
$_fileConfig | array | Holds config options for opening the file. | |
$_filters | array | Storage for filter callbacks to be executed during the parsing stage. | |
$_flushOnAfterFilter | boolean | Whether or not to flush empty rows after filtering. | |
$_garbageCollection | boolean | Whether or not to do garbage collection after parsing. | |
$_rows | array | Storage for parsed CSV rows. |
Method | Description | |
---|---|---|
__construct ( string $filename, string $open_mode = 'r', boolean $use_include_path = false ) : |
Constructor for CSV. | |
__toString ( ) : string | If you cast a CSV instance as a string it will print the contents on the CSV to an HTML table. | |
_applyFilters ( array $row ) : array | Apply filters to the given row. | |
collectGarbage ( boolean $collect = true ) : |
Whether or not to use garbage collection after parsing. | |
filter ( integer | callable $column, callable $callable = null ) : |
Allows you to register any number of filters on a particular column or an entire row. | |
flushEmptyRows ( boolean $onAfterFilter = null ) : |
Flush rows that have turned out empty, either after applying filters or rows that simply have been empty in the source CSV from the get-go. | |
flushFilters ( ) : |
Flushes all active filters. | |
getInstance ( string $filename, $open_mode = 'r', $use_include_path = false ) : |
Get an instance of CSV, based on the filename. | |
getIterator ( ) : ArrayIterator | Get an array iterator for the CSV rows. | |
parse ( integer $rowOffset ) : |
This method will convert the csv to an array and will run all registered filters against it. | |
setDelimiter ( string $delimiter ) : object | Set a delimiter for the CSV file. | |
toJSON ( ) : string | Use this to get the entire CSV in JSON format. | |
toTable ( ) : string | This is a great way to display the filtered contents of the csv to you during the development process (for debugging purposes). |
Method | Description | |
---|---|---|
_flushEmptyRow ( mixed $row, mixed $index, boolean $trim = false ) : void | Flush a row if it's empty. | |
_resolveFilename ( &$filename, boolean $use_include_path = false ) : boolean | Resolve a given filename, keeping include paths in mind. |
public __toString ( ) : string | ||
return | string | $this->toTable() HTML table of CSV contents |
public _applyFilters ( array $row ) : array | ||
$row | array | |
return | array | $row |
public collectGarbage ( boolean $collect = true ) : |
||
$collect | boolean | |
return | $this |
public filter ( integer | callable $column, callable $callable = null ) : |
||
$column | integer | callable | Specific column number or the callable to be applied. Optional: Zero-based column number. If this parameter is preset the $callable will recieve the contents of the current column (as a string), and will receive the entire (array based) row otherwise. |
$callable | callable | Either the current row (as an array) or the current column (as a string) as the first parameter. The callable must return the new filtered row or column. Note: You can also use any native PHP functions that permit one parameter and return the new value, like trim, htmlspecialchars, urlencode, etc. |
return | $this |
public flushEmptyRows ( boolean $onAfterFilter = null ) : |
||
$onAfterFilter | boolean | whether or not to trigger while parsing. Leave this blank to trigger a flush right now. |
return | $this |
public flushFilters ( ) : |
||
return | $this |
public static getInstance ( string $filename, $open_mode = 'r', $use_include_path = false ) : |
||
$filename | string | the CSV file to read. Should be readable. Filenames will be resolved. Symlinks will be followed. |
return | self::$_instances[$key] |
public getIterator ( ) : ArrayIterator | ||
return | ArrayIterator |
public parse ( integer $rowOffset ) : |
||
$rowOffset | integer | Determines which row the parser will start on. Zero-based index. Note: When using a row offset, skipped rows will never be parsed nor stored. As such, we encourage to use different instances when mixing offsets, to prevent resultsets from interfering. |
return | $this |
public setDelimiter ( string $delimiter ) : object | ||
$delimiter | string | |
return | object | $this CSV instance |
protected SplFileObject $_file | ||
return | SplFileObject |
protected array $_fileConfig | ||
return | array |
protected array $_filters | ||
return | array |
protected bool $_flushOnAfterFilter | ||
return | boolean |
protected bool $_garbageCollection | ||
return | boolean |