Laravel 4 - CSV Reader
, (*1)
Server Requirement
This package is require PHP 5.4 or higher., (*2)
Installation
Open your composer.json file, and add the new required package., (*3)
"pingpong/csv-reader": "1.0.*"
Next, open a terminal and run., (*4)
composer update
Next, Add new aliases in app/config/app.php., (*5)
'CsvReader' => 'Pingpong\CsvReader\Facades\CsvReader',
Done., (*6)
Usage
Create new instance., (*7)
$path = app_path('file.csv');
$csv = CsvReader::get($path);
// OR
$csv = CsvReader::make($path);
Get data., (*8)
$data = $csv->getData();
Get data as array., (*9)
$data = $csv->toArray();
Get data as json., (*10)
$data = $csv->toJson();
Get data as object., (*11)
$data = $csv->toObject();
Looping., (*12)
foreach($csv as $item)
{
var_dump($item);
}
Without Laravel
Basically all functions and APIs same as above., (*13)
$path = __DIR__ . '/path/to/csvfile.csv';
$csv = new Pingpong\CsvReader\CsvReader($path);
$data = $csv->getData();
License
This package is open-sourced software licensed under The BSD 3-Clause License, (*14)