2017 © Pedro Peláez
 

library csv

Easily generate CSV files

image

mnshankar/csv

Easily generate CSV files

  • Monday, July 18, 2016
  • by mnshankar
  • Repository
  • 3 Watchers
  • 44 Stars
  • 97,647 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 10 Forks
  • 5 Open issues
  • 10 Versions
  • 9 % Grown

The README.md

Build Status, (*1)

Easy CSV file manipulation (Read, Write and Download)

This is a simple utility package that helps you work with CSV files., (*2)

Installation with Composer

Add this line to your composer.json file in the `require field:, (*3)

"mnshankar/CSV": "1.8"

Generic PHP Project or Laravel 5+ Project

Since this package does not have any framework specific dependencies (or any dependencies for that matter), directly instantiate a CSV object in your code like so, (*4)

$csvObj = new mnshankar\CSV\CSV();

Then, use regular PHP object calls like so:, (*5)

$arr = array(
    array('col1'=>'a','col2'=>'b'),
    array('col1'=>'1','col2'=>'2'),
    array('col1'=>'3','col2'=>'4'),
);
return $csvObj->fromArray($arr)->render('myfile.csv');                  //download as csv;
return $csvObj->fromArray($arr)->withSeparator()->render('myfile.csv'); //add delimiter for better excel compatibility & download
return $csvObj->with($arr)->put('/downloads/myusers.csv');              //store as csv in this path
return $csvObj->fromFile('/downloads/my.csv')->toArray();               //return csv file as an array
return $csvObj->fromFile('/downloads/my.csv')->render('abc.csv');       //render saved csv file as a downloadable document
return $csvObj->with('/downloads/my.csv')->render('abc.csv');           //use 'with'.. same as previous

Laravel 4

CSV has (optional) support for Laravel, and comes with a Service Provider and Facades for easy integration. Open app/config/app.php and add the following line in the providers array:, (*6)

'providers' => array(
    'mnshankar\CSV\CSVServiceProvider',
)

and the following in the 'alias' array, (*7)

'alias' => array(
    'CSV'             =>'mnshankar\CSV\CSVFacade',
)

Now, in your application you can work with CSV files like so:, (*8)

$arr = User::all()->toArray();  //use eloquent to get array of all users in 'users' table

return CSV::with($arr)->put(storage_path().'/downloads/myusers.csv');   //store as csv in this path
return CSV::fromArray($arr)->render();  //download as csv
return CSV::fromFile(storage_path().'/downloads/my.csv')->toArray();    //return csv file as an array
return CSV::fromFile(storage_path().'/downloads/my.csv')->render('abc.csv'); //render saved csv file as a downloadable document
return CSV::with(storage_path().'/downloads/my.csv')->render('abc.csv'); //use 'with'.. same as previous

Note that the 'with' statement can accept either an array or file path, and work accordingly., (*9)

License

This is open-sourced software licensed under the MIT license, (*10)

The Versions

18/07 2016

dev-master

9999999-dev

Easily generate CSV files

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Shankar Manamalkav

17/08 2015

1.8

1.8.0.0

Easily generate CSV files

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Shankar Manamalkav

14/08 2015

1.7

1.7.0.0

Easily generate CSV files

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Shankar Manamalkav

03/05 2015

1.6

1.6.0.0

Easily generate CSV files

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Shankar Manamalkav

25/02 2015

1.5

1.5.0.0

Easily generate CSV files

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Shankar Manamalkav

24/02 2015

1.4

1.4.0.0

Easily generate CSV files

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Shankar Manamalkav

04/02 2015

1.3

1.3.0.0

Easily generate CSV files in Laravel 4

  Sources   Download

MIT

The Requires

 

by Shankar Manamalkav

20/05 2014

1.2

1.2.0.0

Easily generate CSV files in Laravel 4

  Sources   Download

MIT

The Requires

 

by Shankar Manamalkav

10/01 2014

1.1

1.1.0.0

Easily generate CSV files in Laravel 4

  Sources   Download

MIT

The Requires

 

by Shankar Manamalkav

01/12 2013

1.0

1.0.0.0

Easily generate CSV files in Laravel 4

  Sources   Download

MIT

The Requires

 

by Shankar Manamalkav