Download the PHP package kzykhys/php-csv-parser without Composer
On this page you can find all versions of the php package kzykhys/php-csv-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kzykhys/php-csv-parser
More information about kzykhys/php-csv-parser
Files in kzykhys/php-csv-parser
Package php-csv-parser
Short Description Convert CSV to array (Excel style is fully suppoted!)
License MIT
Informations about the package php-csv-parser
PHPCsvParser
Convert CSV to array/Iterator (Excel style is fully suppoted!)
Why PHPCsvParser?
As you know, PHP has built-in fgetcsv
function.
But has some probrems:
- Line breaks in the cell
- Multibyte string (especially NON UTF-8)
- Double quote in the cell
Requirements
PHP5.3.3 or later
Installation
Create or modify your composer.json
And run
Usage
Parse a CSV file
This is the same as:
Parse from string
Parse from array/Iterator
Handling Large files
The class \KzykHys\CsvParser\CsvParser
itself is Traversable
.
so You can convert CSV lines on-the-fly.
Following example is the best choice for performance:
Options
You can pass the options to 2nd argument of each static methods.
- CsvParser::fromFile($file, $options);
- CsvParser::fromString($string, $options);
- CsvParser::fromArray($array, $options);
- new CsvParser($iterator, $options);
Available options are:
Option | Type | Description | Default |
---|---|---|---|
delimiter | string | The field delimiter (one character only) | , |
enclosure | string | The field enclosure character (one character only) | " |
encoding | string | The type of encoding | CP932 |
offset | integer (>=0) | The sequence will start at that offset | 0 |
limit | integer (>=-1) | Limit maximum count of records | -1 (unlimited) |
header | array or false | Use the specified index instead of the column number | false |
Testing
Just run phpunit
(PHPUnit is required)
Author
Kazuyuki Hayashi (@kzykhys)
Changelog
see CHANGELOG
License
The MIT License