summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md20
-rw-r--r--examples/download.php (renamed from examples/example02.php)0
-rw-r--r--examples/example.css53
-rw-r--r--examples/example05.php55
-rw-r--r--examples/extract.php (renamed from examples/example03.php)9
-rw-r--r--examples/filtering.php (renamed from examples/example04.php)7
-rw-r--r--examples/json.php (renamed from examples/example01.php)0
-rw-r--r--examples/switchmode.php (renamed from examples/example06.php)5
-rw-r--r--examples/table.php (renamed from examples/example00.php)5
-rw-r--r--examples/writing.php42
10 files changed, 110 insertions, 86 deletions
diff --git a/examples/README.md b/examples/README.md
deleted file mode 100644
index bfe1c12..0000000
--- a/examples/README.md
+++ /dev/null
@@ -1,20 +0,0 @@
-Examples
-==========
-
-
-* [Converting the CSV into a HTML Table](example00.php) with the `toHTML` method
-* [Converting the CSV into a Json String](example01.php) string
-* [Downloading the CSV](example02.php) using the `output` method
-* [Selecting specific rows in the CSV](example03.php)
-* [Filtering a CSV](example04.php) using the `Bakame\Csv\Reader` class
-* [Creating a CSV](example05.php) using the `Bakame\Csv\Writer` class
-* [From writing mode to reader mode](example06.php)
-
-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.
-
-* 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/example02.php b/examples/download.php
index 3e017b6..3e017b6 100644
--- a/examples/example02.php
+++ b/examples/download.php
diff --git a/examples/example.css b/examples/example.css
new file mode 100644
index 0000000..9010a26
--- /dev/null
+++ b/examples/example.css
@@ -0,0 +1,53 @@
+html {
+ font:normal 1em/1.5 sans-serif;
+}
+/* taken and adapted from lea verou excellent blog theme */
+pre {
+ margin-bottom: 1em;
+ overflow: auto;
+ padding: .5em .8em;
+ border: 1px solid #aaa;
+ background-color: #e1e1e1;
+ color: #444;
+ font-size: 1.2em;
+ line-height: 1.5;
+ text-align: left;
+ -webkit-tab-size: 4;
+ -moz-tab-size: 4;
+ -ms-tab-size: 4;
+ -o-tab-size: 4;
+ tab-size: 4;
+}
+body {
+ margin:0 auto;
+ width:50%
+}
+.table-csv-data {
+ width:98%;
+ margin:0 auto 1em;
+ border-collapse:collapse;
+ padding:0;
+ font:normal 1em/1.5 sans-serif;
+}
+.table-csv-data td {
+ border-bottom:1px solid #ccc;
+ padding:.3em;
+ color:#222;
+ vertical-align: top;
+ text-align:left;
+}
+
+.table-csv-data tr:nth-child(even) td {
+ background-color:rgba(192, 192, 192, .2);
+}
+
+.table-csv-data tr:hover td {
+ background-color:#d4e8fc;
+}
+
+.with-header tbody tr:first-of-type td {
+ font-weight:bold;
+}
+.with-header tbody tr:first-of-type:hover td {
+ background-color:inherit;
+} \ No newline at end of file
diff --git a/examples/example05.php b/examples/example05.php
deleted file mode 100644
index 33210d3..0000000
--- a/examples/example05.php
+++ /dev/null
@@ -1,55 +0,0 @@
-<?php
-
-use Bakame\Csv\Writer;
-use Bakame\Csv\Reader;
-
-require '../vendor/autoload.php';
-
-$inputCsv = new Reader('data/prenoms.csv');
-$inputCsv->setDelimiter(';');
-$inputCsv->setEncoding("iso-8859-15");
-
-//we filter only the least girl firstname given in 2010
-$filter = function ($row, $index) {
- return $index > 0 //we don't take into account the header
- && isset($row[1], $row[2], $row[3]) //we make sure the data are present
- && 10 > $row[1] //the name is used less than 10 times
- && 2010 == $row[3] //we are looking for the year 2010
- && 'F' == $row[2]; //we are only interested in girl firstname
-};
-
-//we order the result according to the number of firstname given
-$sortBy = function ($row1, $row2) {
- return strcmp($row1[1], $row2[1]);
-};
-
-$res = $inputCsv
- ->setFilter($filter)
- ->setSortBy($sortBy)
- ->setLimit(20) //we just want the first 20 results
- ->fetchAll();
-
-$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);
-?>
-<!doctype html>
-<html lang="fr">
-<head>
- <meta charset="<?=$inputCsv->getEncoding()?>">
- <title>Example 2</title>
-</head>
-<body>
-<h1>Example 4: Using Writer object</h1>
-<h3>The table representation of the csv to be save</h3>
-<?=$writer->toHTML();?>
-<h3>The Raw CSV as it will be saved</h3>
-<pre>
-<?=$writer?>
-</pre>
-<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/example03.php b/examples/extract.php
index 2eb08e2..9e884fa 100644
--- a/examples/example03.php
+++ b/examples/extract.php
@@ -11,18 +11,19 @@ $inputCsv->setEncoding("iso-8859-15");
//get the header
$headers = $inputCsv->fetchOne(0);
-//get at maximum 40 rows starting from the second 801th row
+//get at maximum 25 rows starting from the second 801th row
$res = $inputCsv->setOffset(800)->setLimit(25)->fetchAll();
?>
<!doctype html>
<html lang="fr">
<head>
<meta charset="<?=$inputCsv->getEncoding()?>">
- <title>Example 1</title>
+ <title>\Bakame\Csv\Reader simple usage</title>
+ <link rel="stylesheet" href="example.css">
</head>
<body>
-<h1>Example 1: Simple Reader class usage</h1>
-<table>
+<h1>\Bakame\Csv\Reader simple usage</h1>
+<table class="table-csv-data">
<caption>Part of the CSV from the 801th row with at most 25 rows</caption>
<thead>
<tr>
diff --git a/examples/example04.php b/examples/filtering.php
index 213425f..61fcb4d 100644
--- a/examples/example04.php
+++ b/examples/filtering.php
@@ -36,11 +36,12 @@ $headers = $inputCsv->fetchOne(0);
<html lang="fr">
<head>
<meta charset="<?=$inputCsv->getEncoding()?>">
-<title>Example 3</title>
+ <title>\Bakame\Csv\Reader filtering method</title>
+ <link rel="stylesheet" href="example.css">
</head>
<body>
-<h1>Example 3: Using the Reader class filtering capabilities</h1>
-<table>
+<h1>Using the Bakame\Csv\Reader class filtering capabilities</h1>
+<table class="table-csv-data">
<caption>Statistics for the 20 least used female name in the year 2010</caption>
<thead>
<tr>
diff --git a/examples/example01.php b/examples/json.php
index b4caf2e..b4caf2e 100644
--- a/examples/example01.php
+++ b/examples/json.php
diff --git a/examples/example06.php b/examples/switchmode.php
index 6ddf30c..df480eb 100644
--- a/examples/example06.php
+++ b/examples/switchmode.php
@@ -56,10 +56,11 @@ $names = $reader
<html lang="fr">
<head>
<meta charset="utf-8">
- <title>Example 2</title>
+ <title>Bakame\Csv\Writer and Bakame\Csv\Reader switching mode</title>
+ <link rel="stylesheet" href="example.css">
</head>
<body>
-<h1>Example 4: Using Writer object with Strings</h1>
+<h1>Using createFromString method and converting the Bakame\Csv\Writer into a Bakame\Csv\Reader</h1>
<h3>The table representation of the csv to be save</h3>
<?=$writer->toHTML();?>
<h3>The Raw CSV as it will be saved</h3>
diff --git a/examples/example00.php b/examples/table.php
index be353d0..5c26ddb 100644
--- a/examples/example00.php
+++ b/examples/table.php
@@ -12,9 +12,10 @@ $inputCsv->setEncoding("iso-8859-15");
<html lang="fr">
<head>
<meta charset="<?=$inputCsv->getEncoding()?>">
- <title>Example 2</title>
+ <title>Using the toHTML() method</title>
+ <link rel="stylesheet" href="example.css">
</head>
<body>
-<?=$inputCsv->toHTML();?>
+<?=$inputCsv->toHTML('table-csv-data with-header');?>
</body>
</html>
diff --git a/examples/writing.php b/examples/writing.php
new file mode 100644
index 0000000..948008a
--- /dev/null
+++ b/examples/writing.php
@@ -0,0 +1,42 @@
+<?php
+
+use Bakame\Csv\Writer;
+
+require '../vendor/autoload.php';
+
+$writer = new Writer(new SplTempFileObject); //the CSV file will be created into a temporary File
+$writer->setDelimiter("\t"); //the delimiter will be the tab character
+$writer->setEncoding("utf-8");
+
+$headers = ["position" , "team", "played", "goals difference", "points"];
+$writer->insertOne($headers);
+
+$teams = [
+ [1, "Chelsea", 26, 27, 57],
+ [2, "Arsenal", 26, 22, 56],
+ [3, "Manchester City", 25, 41, 54],
+ [4, "Liverpool", 26, 34, 53],
+ [5, "Tottenham", 26, 4, 50],
+ [6, "Everton", 25, 11, 45],
+ [7, "Manchester United", 26, 10, 42],
+];
+
+$writer->insertAll($teams);
+?>
+<!doctype html>
+<html lang="fr">
+<head>
+ <meta charset="<?=$writer->getEncoding()?>">
+ <title>Using the \Bakame\Writer object</title>
+ <link rel="stylesheet" href="example.css">
+</head>
+<body>
+<h1>Example 4: Using Writer object</h1>
+<h3>The table representation of the csv</h3>
+<?=$writer->toHTML('table-csv-data with-header');?>
+<h3>The Raw CSV to be saved</h3>
+<pre>
+<?=$writer?>
+</pre>
+</body>
+</html>