A simple library to interact with CSV elements

v1.0.0 2022-08-25 16:11 UTC

This package is auto-updated.

Last update: 2024-10-25 20:49:55 UTC


README

This library is a super simple abstraction layer for working with CSV files.

Examples

Reading Files

/*
 * path/to/file.csv -
 * foo,bar
 * bing,baz
 * one,two
 */
$reader = new \Judahnator\CSV\Reader(new SplFileInfo('path/to/file.csv'));
foreach ($reader as ['foo' => $foo, 'bar' => $bar]) {
    echo $foo, ' ', $bar, PHP_EOL;
}
/*
 * prints:
 * bing baz
 * one two
 */

Writing Files

$writer = new \Judahnator\CSV\Writer(new SplFileInfo('path/to/file.csv'));
$writer->write([
    ['foo', 'bar'],
    ['bing', 'baz'],
    ['one', 'two'],
]);
// The file now contains the same as the above example