Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuno Chaves authored Dec 21, 2017
1 parent 26d8aea commit 2ead4a1
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ Include jupitern/file-parser in your project, by adding it to your composer.json
```php

Given a csv file "filename.csv" with contents (animal, category, count):
animal,type,count
crocodile,reptile,4
dolphin,mammal,0
duck,bird,2
koala,mammal,4
lion,mammal,5

lets parse the file with:
- ignore the first line
- convert encoding to ISO-9959-1
- convert lines to objects
- remove animals with count 0
Expand All @@ -40,9 +42,9 @@ lets parse the file with:
$objectsArr = \Jupitern\Parser\FileParser::instance()
->setFile("csv.txt", ',')
->setEncoding('ISO-8859-1', 'UTF-8')
->toObject(['animal', 'type', 'number'])
->filter(function ($line) {
return $line->number > 0;
->toObject(['animal', 'type', 'animalCount'])
->filter(function ($line, $lineNumber) {
return $lineNumber > 1 && $line->animalCounnt > 0;
})
->format('type', function ($val) {
return strtoupper($val);
Expand Down

0 comments on commit 2ead4a1

Please sign in to comment.