summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgnace Nyamagana Butera <nyamsprod@gmail.com>2014-02-07 10:58:13 +0100
committerIgnace Nyamagana Butera <nyamsprod@gmail.com>2014-02-07 10:58:13 +0100
commit55d02f8f0f987ca5904d34bc56d022e020595d66 (patch)
treeccd2038b5d407bb9084e1cf22bd21392accbe3ff
parentbfb61f0f466bba7df3fbc09208a4f40c3460276b (diff)
downloadcsv-55d02f8f0f987ca5904d34bc56d022e020595d66.zip
csv-55d02f8f0f987ca5904d34bc56d022e020595d66.tar.gz
csv-55d02f8f0f987ca5904d34bc56d022e020595d66.tar.bz2
examples update
-rw-r--r--examples/README.md12
-rw-r--r--examples/example00.php3
-rw-r--r--examples/example01.php3
-rw-r--r--examples/example02.php3
-rw-r--r--examples/example03.php16
-rw-r--r--examples/example04.php9
-rw-r--r--examples/example05.php9
-rw-r--r--examples/example06.php24
8 files changed, 29 insertions, 50 deletions
diff --git a/examples/README.md b/examples/README.md
index 4ed3acf..e524a4f 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -3,16 +3,18 @@ Examples
* [Converting the CSV into a HTML Table](example00.php) with the `toHTML` method
-* [Converting the CSV into a Json](example01.php) string
+* [Converting the CSV into a Json String](example01.php) string
* [Downloading the CSV](example02.php) using the `output` method
-* [Selecting a specific row in the CSV](example03.php)
+* [Selecting specific rows in the CSV](example03.php)
* [Filtering a CSV](example05.php) using the `Bakame\Csv\Reader` class
* [Creating a CSV](example05.php) using the `Bakame\Csv\Writer` class
-* [Passing a CSV from writing mode to Reader mode](example06.php)
+* [From writing mode to reader mode](example06.php)
-The CSV use for the example is from [Paris Opendata](http://opendata.paris.fr/opendata/jsp/site/Portal.jsp?document_id=60&portlet_id=121)
+The CSV data use for the examples are taken from [Paris Opendata](http://opendata.paris.fr/opendata/jsp/site/Portal.jsp?document_id=60&portlet_id=121)
Tips
------
-When creating a file using the `Bakame\Csv\Writer` class, first use the `insert*` methods and manipulate your CSV afterwards. If you manipulate your data before you may change the file cursor position and get unexpected results. \ No newline at end of file
+* When creating a file using the `Bakame\Csv\Writer` class, first use the `insert*` methods and manipulate your CSV afterwards. If you manipulate your data before you may change the file cursor position and get unexpected results.
+
+* If your are dealing with non-unicode data, please don't forger to specify the encoding parameter using the `setEncoding` method otherwise you json conversion may no work. \ No newline at end of file
diff --git a/examples/example00.php b/examples/example00.php
index a286428..be353d0 100644
--- a/examples/example00.php
+++ b/examples/example00.php
@@ -1,8 +1,5 @@
<?php
-error_reporting(-1);
-ini_set('display_errors', 'On');
-
use Bakame\Csv\Reader;
require '../vendor/autoload.php';
diff --git a/examples/example01.php b/examples/example01.php
index e510a5d..b4caf2e 100644
--- a/examples/example01.php
+++ b/examples/example01.php
@@ -1,8 +1,5 @@
<?php
-error_reporting(-1);
-ini_set('display_errors', 'On');
-
use Bakame\Csv\Reader;
require '../vendor/autoload.php';
diff --git a/examples/example02.php b/examples/example02.php
index 9d78293..3e017b6 100644
--- a/examples/example02.php
+++ b/examples/example02.php
@@ -1,8 +1,5 @@
<?php
-error_reporting(-1);
-ini_set('display_errors', 'On');
-
use Bakame\Csv\Reader;
require '../vendor/autoload.php';
diff --git a/examples/example03.php b/examples/example03.php
index 3497c00..2eb08e2 100644
--- a/examples/example03.php
+++ b/examples/example03.php
@@ -1,8 +1,5 @@
<?php
-error_reporting(-1);
-ini_set('display_errors', 'On');
-
use Bakame\Csv\Reader;
require '../vendor/autoload.php';
@@ -14,9 +11,8 @@ $inputCsv->setEncoding("iso-8859-15");
//get the header
$headers = $inputCsv->fetchOne(0);
-//get all the data without the header
-$res = $inputCsv->setOffset(1)->fetchAll();
-
+//get at maximum 40 rows starting from the second 801th row
+$res = $inputCsv->setOffset(800)->setLimit(25)->fetchAll();
?>
<!doctype html>
<html lang="fr">
@@ -27,14 +23,10 @@ $res = $inputCsv->setOffset(1)->fetchAll();
<body>
<h1>Example 1: Simple Reader class usage</h1>
<table>
-<caption>Full Statistics</caption>
+<caption>Part of the CSV from the 801th row with at most 25 rows</caption>
<thead>
<tr>
-<?php foreach ($headers as $title): ?>
- <th><?=$title?></th>
- <?php
-endforeach;
-?>
+ <th><?=implode('</th>'.PHP_EOL.'<th>', $headers), '</th>', PHP_EOL; ?>
</tr>
</thead>
<tbody>
diff --git a/examples/example04.php b/examples/example04.php
index e0cb41f..213425f 100644
--- a/examples/example04.php
+++ b/examples/example04.php
@@ -1,8 +1,5 @@
<?php
-error_reporting(-1);
-ini_set('display_errors', 'On');
-
use Bakame\Csv\Reader;
require '../vendor/autoload.php';
@@ -47,11 +44,7 @@ $headers = $inputCsv->fetchOne(0);
<caption>Statistics for the 20 least used female name in the year 2010</caption>
<thead>
<tr>
-<?php foreach ($headers as $title): ?>
- <th><?=$title?></th>
- <?php
-endforeach;
-?>
+ <th><?=implode('</th>'.PHP_EOL.'<th>', $headers), '</th>', PHP_EOL; ?>
</tr>
</thead>
<tbody>
diff --git a/examples/example05.php b/examples/example05.php
index 74cbffc..33210d3 100644
--- a/examples/example05.php
+++ b/examples/example05.php
@@ -1,10 +1,7 @@
<?php
-error_reporting(-1);
-ini_set('display_errors', 'On');
-
-use Bakame\Csv\Reader;
use Bakame\Csv\Writer;
+use Bakame\Csv\Reader;
require '../vendor/autoload.php';
@@ -35,6 +32,7 @@ $res = $inputCsv
$headers = $inputCsv->fetchOne(0);
$writer = new Writer(new SplTempFileObject); //because we don't want to create the file
+$writer->setDelimiter("\t"); //the delimiter will be the tab character
$writer->insertOne($headers);
$writer->insertAll($res);
?>
@@ -52,7 +50,6 @@ $writer->insertAll($res);
<pre>
<?=$writer?>
</pre>
-<p><em>Notice that the delimiter have changed from <code>;</code> to <code>,</code></em></p>
-</ol>
+<p><em>Notice that the delimiter have changed from <code>;</code> to <code>&lt;tab&gt;</code></em></p>
</body>
</html>
diff --git a/examples/example06.php b/examples/example06.php
index b62d491..6ddf30c 100644
--- a/examples/example06.php
+++ b/examples/example06.php
@@ -1,8 +1,5 @@
<?php
-error_reporting(-1);
-ini_set('display_errors', 'On');
-
use Bakame\Csv\Writer;
require '../vendor/autoload.php';
@@ -15,9 +12,11 @@ Andrea;20;F;2004
Andy;19;M;2004
Ange;15;M;2004
Angela;9;F;2004
-Angèle;29;F;2004
-Angelina;8;F;2004
-Angelina;7;F;2004
+Kelyan;6;M;2011
+Kenan;11;M;2011
+Kenny;8;M;2011
+Kenza;33;F;2011
+Kenzi;5;M;2011
Angelique;13;F;2004
Angelo;9;M;2004
Ania;7;F;2004
@@ -32,15 +31,20 @@ Antoine;248;M;2004
Anton;16;M;2004
EOF;
-$writer = Writer::createFromString($rawCsv); //we are creating a CSV from a raw string
+ //we are creating a CSV from a raw string
+$writer = Writer::createFromString($rawCsv);
+
+//because we raw string delimiter is ";"
+//the string delimiter MUST also be ";"
$writer->setDelimiter(';');
-$writer->insertOne('Ben;7;M;2004'); //because we specified the delimiter to ";" the string delimiter MUST also be ";"
+
+$writer->insertOne('Ben;7;M;2004');
$writer->insertAll([
'Benjamin;118;M;2004',
- ['Benoit', '6', 'M', '2004'] //because we a inserting an array the delimiter is not necessary
+ ['Benoit', '6', 'M', '2004']
]);
-//we create a Reader object from the Writer object to filter the resulting CSV
+//we create a Reader object from the Writer object
$reader = $writer->getReader();
$names = $reader
->setSortBy(function ($row1, $row2) {