Skip to content

Commit

Permalink
Merge pull request #2 from rana7cse/develop
Browse files Browse the repository at this point in the history
okey
  • Loading branch information
rana7cse authored Aug 19, 2018
2 parents 89fc550 + e6a2317 commit a23c1c8
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,41 @@
# yocsv

**YoCsv** is a simple php package to manipulate `csv` files and it's data easily. This package also allow you to transform your expected data from `csv` file data.
**YoCsv** is a simple php package to manipulate `csv` files and apply query on it's data like [jsonq](https://github.com/nahid/jsonq). This package also allow you to transform your expected data.

## Installation
Just add this package to your `composer.json` file to write this command.
```
composer require msrana/yocsv
```

## Basic usage to read a csv file
Just create an instance of `CsvReader` class and pass an argument of file path `string`. Then call the `get()` method to get data like example below
## Quick usage to read a csv file
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
```php
use \Rana\YoCsvPHP\Csv\CsvReader;
$csv = new CsvReader("../source/school.csv") // use right path name to ignore `FileNotFoundException`
$data = $csv->get();
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** `vendor/autoload.php` file.

Sometimes you may need csv file's first row as array key. To get first row as array key just call `firstRowAsTitle()` method before `get()` method like this.
`Or` you can instantiate without passing any argument on `constractor` in this way you have to call `read` or `import` method with a argument as file path.
```php
use \Rana\YoCsvPHP\Csv\CsvReader;
$csv = new CsvReader("../source/school.csv");
$data = $csv->firstRowAsTitle()->get(); // return an array of all data
use MsRana\YoCsv\Csv;
$csv = new Csv();
$csv->read("file.csv");
$csv->get(); // return all data row as array
```

This package also allow you iterate over individual row. To do this type of iteration call `$csv->each(callback)` method that's take an argument as callback like below
This package also allow you to apply query/filters like as orm. We use [jsonq](https://github.com/nahid/jsonq) package to inherit it's query functionality on csv file.
It's will be really useful for us to read [JsonQ documentation](https://github.com/nahid/jsonq) from here.
```php
$csv->each(function($row){
// you will get data from $row
});
```
$csv->where('key',$value);
$csv->get(); // show result
```

## Library used
* [thephpleague/csv](https://github.com/thephpleague/csv)
* [nahid/jsonq](https://github.com/nahid/jsonq)

## Credit
* [Shipu Ahamed](https://github.com/shipu) [guti korse]
* [Nahid Bin Azhar](https://github.com/nahid) [fasai dise]

0 comments on commit a23c1c8

Please sign in to comment.