Reader
abstract class Reader (View source)
Constants
| MODE_COLUMN |
|
| SKIP_BLANK |
|
| SKIP_HEADER |
|
| STRICT |
|
Properties
| protected | $separator | ||
| protected | $separators | ||
| protected | $stream |
Methods
Open file
No description
Get headers from file
Get file pointer resource
Rewind the position of file pointer and refresh headers
Set maximum line length
Set Data Transfer Object class
Set end-of-line
Set the behavior of the fetch() method, and returns the previously defined flags.
Set a custom filter that can be used to skip specific rows by returning false
in the callback, or simply to modify the values received by reference.
Set the maximum number of rows returned and skips a certain number of rows before starting to return rows.
Fetch a row from file pointer
Details
__construct(string $path)
Open file
__destruct()
No description
array<int, string>
getHeaders()
Get headers from file
resource
getStream()
Get file pointer resource
refresh()
Rewind the position of file pointer and refresh headers
setChunk(int|null $length)
Set maximum line length
setDataTransferObject(string|null $dto)
Set Data Transfer Object class
Note: To ensure the key format, use setFilter() method.
setEndOfLine(string $eol)
Set end-of-line
int
setFlags(int $flags)
Set the behavior of the fetch() method, and returns the previously defined flags.
callable
setFilter(callable $filter)
Set a custom filter that can be used to skip specific rows by returning false
in the callback, or simply to modify the values received by reference.
Note: For headers, the filter is only used to modify the values. Note: When defining a callback, the previous callback will be returned.
E.g:
$handle->setFilter(function (array &$fields, $index) {
if ($index === 0) {
// Convert header
$fields = str_to_snake_case($fields);
} else {
// Convert rows
$field = array_map('stripcslashes', $field);
}
});
setLimit(int $count, int $offset = 0)
Set the maximum number of rows returned and skips a certain number of rows before starting to return rows.
Note: If this method is not used, it will be limited to 1000 rows.
array<int, string>|array<string, string>|false
fetch()
Fetch a row from file pointer
Converter
converter()
Get a Converter instance.