CSV easy import and export with php
YoCsv is a simple php package to manipulate
csv files and apply query on it's data like php-jsonq. This package also allow you to transform your expected data.
Just add this package to your
composer.json file to write this command.
composer require msrana/yocsv
Just create an instance of
Csv class and pass an argument of file path
string. Then call the
get() method to get data like example below
use MsRana\YoCsv\Csv; $csv = new Csv("../source/school.csv") // use right path name to ignore `FileNotFoundException` $data = $csv->get(); // you will get all row as array
Please don't forget to add
Or you can instantiate without passing any argument on
constractor in this way you have to call
import method with a argument as file path.
use MsRana\YoCsv\Csv; $csv = new Csv(); $csv->read("file.csv"); $csv->get(); // return all data row as array
This package also allow you to apply query/filters like as orm. We use php-jsonq package to inherit it's query functionality on csv file. Please read php-jsonq documentation and their apis to apply query on csv :D.
$csv->where('key',$value); $csv->get(); // show result