Wallogit.com
2017 © Pedro Peláez
Powerful tool for csv files
This is a very powerful tool for reading, creating, updating or downloading a csv file. Also you can read file from the end., (*1)
The preferred way to install this tool is through composer., (*2)
Either run, (*3)
php composer.phar require stdakov/csv
or add, (*4)
"stdakov/csv": "*"
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, (*5)
$file = 'export.csv'; //It is optional
Also you can show in witch folder file will be saved., (*6)
$path = 'somePath'; //It is optional
Create instance, (*7)
$csv = new \Dakov\CSV();
or with custom file and path, (*8)
$csv = new \Dakov\CSV($path); $csv->setFile($file);
Example data for insert:, (*9)
$data = [
[
'column1' => 1,
'column2' => 1,
],
[
'column1' => 2,
'column2' => 2,
],
];
Insert and create file with data, (*10)
$csv->create($data);
Example data for append:, (*11)
$data = [
[
'column1' => 3,
'column2' => 3,
],
[
'column1' => 4,
'column2' => 4,
],
[
'column1' => 5,
'column2' => 5,
],
];
Append some data to the file:, (*12)
$csv->append($data);
Return assoc array with all data:, (*13)
print_r($csv->read());
Return assoc array with all reverse data:, (*14)
print_r($csv->readReverse());
You can set line limit (it is optional), (*15)
print_r($csv->readReverse(2));
Download file, (*16)
$csv->download();
also you can delete file after download, (*17)
$csv->download(true);
The MIT License (MIT), (*18)