A class for creating CSV files, allowing you to set a custom end-of-line character
This class provides the flexibility of creating CSV files in PHP with a custom end-of-line character.
fputcsv function allows you to specify a field delimiter, but strangely doesn't let you set the EOL character - which, when it insists on
isn't always helpful when the files are destined for people to view/edit on a Windows based systems.
To install via Composer:
composer require chrismou/php-eol-csv
Instantiate the class:
$csv = new \Chrismou\PhpEolCsv\Csv;
Open a CSV file for editing:
$csv->open($fileName, $savePath, $eol, $fileExtension, $delimiter, $enclosure);
- $fileName (required) - the filename to use. Don't include the file extension, this can be set seperately.
- $savePath - The path to save the file. Leaving this blank will save directly to the output buffer for a direct download.
- $eol - The EOL character/string to use. Defaults to
- $fileExtension - The file extension to use. Defaults to
- $delimiter - The character/string to use as a separator between fields. Defaults to
- enclosure - The character to use to enclose multi-word strings, or strings that include the delimiter character. Defaults to
Write a row to the CSV:
$csv->write(array("Field1", "Field2", "Field3"));
Finish editing and close the file:
PHP 5.3 upwards, including HHVM.
To run the unit test suite:
curl -s https://getcomposer.org/installer | php php composer.phar install ./vendor/bin/phpunit
A DUnit config file is also included, allowing you to easily run tests on all supported PHP versions.
First, you need to have docker installed. This is fairly simple on Linux - on OSX and Windows, take a look at docker machine.
Assuming you have composer setup (see above), run the tests with the following command:
Released under the MIT License. See LICENSE.md.