diff options
author | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2014-02-14 10:59:05 +0100 |
---|---|---|
committer | Ignace Nyamagana Butera <nyamsprod@gmail.com> | 2014-02-14 13:14:36 +0100 |
commit | 061a4d28bb6f889e9c6ff00aaf616e889026517c (patch) | |
tree | 7b369dd05fa28b621c5b996dbffcb0f0467cdd87 /examples/example05.php | |
parent | cfc39411c0645fe782803254cedd682d7fdc494f (diff) | |
download | csv-061a4d28bb6f889e9c6ff00aaf616e889026517c.zip csv-061a4d28bb6f889e9c6ff00aaf616e889026517c.tar.gz csv-061a4d28bb6f889e9c6ff00aaf616e889026517c.tar.bz2 |
Documentation Update
Diffstat (limited to 'examples/example05.php')
-rw-r--r-- | examples/example05.php | 55 |
1 files changed, 0 insertions, 55 deletions
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><tab></code></em></p> -</body> -</html> |