Download the PHP package jeroenzwart/php-csv-iterator without Composer
On this page you can find all versions of the php package jeroenzwart/php-csv-iterator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jeroenzwart/php-csv-iterator
More information about jeroenzwart/php-csv-iterator
Files in jeroenzwart/php-csv-iterator
Package php-csv-iterator
Short Description A simple CSV reader, to read as array/object with PHP Iterator
License GPL-3.0-or-later
Homepage https://github.com/jeroenzwart/php-csv-iterator
Informations about the package php-csv-iterator
PHP CSV Iterator
A simple CSV reader with PHP Iterator
This package is an easy way to read CSV files. The CSV Reader will iterate over a CSV file with low memory usage.
Features
- Returns an array with keys from the headers.
- Reads a specific line in the CSV file.
- Skip the empty lines.
- Reading a CSV file with an offset and/or limit.
Installation
Via Composer
Usage
This example is a part of the CSV file ./csv/movies.csv; `
To loop over each item in the CSV file, you will use the reader like this;
Or use one of the default iterator methods;
Options
filePath
(string) - Path to the CSV file.offset
(integer 0) - The offset from start reading the CSV file.limit
(integer -1) - The limit to end reading the CSV file.delimiter
(string ,) - The delimiter character in the CSV file.enclosure
(string ") - The enclosure character in the CSV file.escape
(string \) - The escape character in the CSV file.hasHeaders
(boolean TRUE) - To set if the CSV file has a header, set FALSE if not.asObject
(boolean TRUE) - Return the lines of the CSV file as object, set FALSE as array.keepEmptyLines
(boolean FALSE) - Set TRUE for keeping an empty lines in the CSV file.
Examples
Offset and limit
Start reading with another position with offset and limit;
Delimiter, enclose and escape
Read with another delimiter, enclose and escape;
To get the current delimiter, enclosure or escape, you use $csv->delimiter()
Headers, asObject and empty
Ignore the headers in the CSV file and return array with regular keys, but keep empty lines;
To get the headers of a CSV file as array, you use $csv->headers()
.
For getting the modes for settings asObject or empty, you can use $csv->asObject()
or $csv->empty()
.
Position
Load a line at a given position;
To get the current position of the iterator, you use $csv->position()
Change log
Please see the changelog for more information on what has changed recently.
License
Please see the license file for more information.