stdakov/csv

Powerful tool for csv files

v1.0 2016-05-18 10:58 UTC

This package is auto-updated.

Last update: 2024-11-29 05:44:21 UTC


README

#CSV tool This is a very powerful tool for reading, creating, updating or downloading a csv file. Also you can read file from the end.

##Installation The preferred way to install this tool is through composer.

Either run

php composer.phar require stdakov/csv

or add

"stdakov/csv": "*"

##Usage

require 'vendor/autoload.php';

Optional: if you want you can use custom filename. It there is no custom filename it will create file with name date("Y-m-d_H:i:s") . '_' . export.csv

$file = 'export.csv'; //It is optional

Also you can show in witch folder file will be saved.

$path = 'somePath'; //It is optional

Create instance

$csv = new \Dakov\CSV();

or with custom file and path

$csv = new \Dakov\CSV($path);
$csv->setFile($file);

Example data for insert:

$data = [
    [
        'column1' => 1,
        'column2' => 1,
    ],
    [
        'column1' => 2,
        'column2' => 2,
    ],
];

Insert and create file with data

$csv->create($data);

Example data for append:

$data = [
    [
        'column1' => 3,
        'column2' => 3,
    ],
    [
        'column1' => 4,
        'column2' => 4,
    ],
    [
        'column1' => 5,
        'column2' => 5,
    ],
];

Append some data to the file:

$csv->append($data);

Return assoc array with all data:

print_r($csv->read());

Return assoc array with all reverse data:

print_r($csv->readReverse());

You can set line limit (it is optional)

print_r($csv->readReverse(2));

Download file

$csv->download();

also you can delete file after download

$csv->download(true);

The MIT License (MIT)