-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from rana7cse/develop
okey
- Loading branch information
Showing
1 changed file
with
24 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |