From 2ead4a1f0126b944aa515d66f8c25544fe34b82f Mon Sep 17 00:00:00 2001 From: Nuno Chaves Date: Thu, 21 Dec 2017 13:46:53 +0000 Subject: [PATCH] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 6d98299..c7a3864 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ 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 @@ -30,6 +31,7 @@ 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 @@ -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);