From ae1176ce780f8528332298c46833c79d91c10ae0 Mon Sep 17 00:00:00 2001 From: Simon Vieille Date: Sun, 12 Mar 2017 15:20:09 +0100 Subject: [PATCH] Documentation --- README.md | 44 +++++++++++++++++++++++++++++------------- src/Deblan/Csv/Csv.php | 2 +- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 7c89d21..ba8c062 100644 --- a/README.md +++ b/README.md @@ -14,8 +14,7 @@ Or in your composer.json: ``` { "require": { - [...] - "deblan/csv": "dev-master" + "deblan/csv": "~2" } } ``` @@ -29,22 +28,41 @@ use Deblan\Csv\Csv; $csv = new Csv(); -$csv->addLine(array('Foo', '$1000')); -$csv->addLine(array('Bar', '$600')); +// Defines the delimiter (default is ;) +$csv->setDelimiter(";"); -$result = $csv->compile(); -``` +// Defines the enclosure (default is ") +$csv->setEnclosure('"'); -```php -use Deblan\Csv\Csv; +// Defines the end of line (default is \n) +$csv->setEndOfLine("\n"); -$csv = new Csv(); +// Defines the charset (default is UTF-8) +$csv->setCharset("UTF-8"); -$csv->setLegend(array('product name', 'price')); -$csv->addLine(array('Foo', '$1000')); -$csv->addLine(array('Bar', '$600')); +// Add a new line at the end +$csv->addData(['Foo', '$1000')); -$csv->compileToFile('products.csv'); +// Add a new line at the end +$csv->appendData(['Bar', '$600']); + +// Add a new line at the beginning +$csv->prependData(['Boo', '$3000']); + +// Defines all the datas +$csv->setDatas([[...], [...]]); + +// Defines the header +$csv->setHeaders(["Product", "Price"]); + +// Rendering +$result = $csv->render(); + +// Rendering to a file +$result = $csv->render("products.csv"); + +// Appending to a file +$result = $csv->render("products.csv", FILE_APPEND); ``` ### Parser diff --git a/src/Deblan/Csv/Csv.php b/src/Deblan/Csv/Csv.php index 6332746..f661bf8 100644 --- a/src/Deblan/Csv/Csv.php +++ b/src/Deblan/Csv/Csv.php @@ -332,7 +332,7 @@ class Csv if ($flags === FILE_APPEND && file_exists($filename)) { $content = $this->endOfLine.$content; } - + file_put_contents($filename, $content, $flags, $context); }