diff --git a/CHANGELOG.md b/CHANGELOG.md index b01742cf..46894f4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All Notable changes to `Csv` will be documented in this file -## Next - 2015-xx-xx +## 8.0.0 - 2015-12-11 ### Added @@ -20,6 +20,7 @@ All Notable changes to `Csv` will be documented in this file - `Reader::fetchColumn` callable argument expects the selected column value as its first argument - Default value on `setOutputBOM` is removed - `AbstractCsv::getOutputBOM` always return a string +- `AbstractCsv::getInputBOM` always return a string ### Removed diff --git a/examples/example.css b/examples/example.css index 9010a260..73180e22 100755 --- a/examples/example.css +++ b/examples/example.css @@ -13,10 +13,10 @@ pre { 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; + -moz-tab-size: 4; + -ms-tab-size: 4; + -o-tab-size: 4; + tab-size: 4; } body { margin:0 auto; diff --git a/examples/extract.php b/examples/extract.php index 53d3e19d..61c768e3 100755 --- a/examples/extract.php +++ b/examples/extract.php @@ -11,17 +11,17 @@ $headers = $inputCsv->fetchOne(0); //get at maximum 25 rows starting from the 801th row -$res = $inputCsv->setOffset(800)->setLimit(25)->fetchAll(); +$res = $inputCsv->setOffset(800)->setLimit(25)->fetch(); ?> - \League\Csv\Reader simple usage + League\Csv\Reader simple usage -

\League\Csv\Reader simple usage

+

League\Csv\Reader simple usage

@@ -32,7 +32,7 @@ - ', PHP_EOL; ?> + ', PHP_EOL; ?> setLimit(20) //we just want the first 20 results - ->fetchAll(); + ->fetch(); //get the headers $headers = $inputCsv->fetchOne(0); @@ -37,7 +37,7 @@ - \League\Csv\Reader filtering method + League\Csv\Reader filtering method diff --git a/examples/json.php b/examples/json.php index b86826e7..60cddc83 100755 --- a/examples/json.php +++ b/examples/json.php @@ -7,6 +7,8 @@ $inputCsv = Reader::createFromPath('data/prenoms.csv'); $inputCsv->setDelimiter(';'); $inputCsv->setEncodingFrom('ISO-8859-15'); +//we limit the output to max. 10 rows +$inputCsv->setLimit(10); $res = json_encode($inputCsv, JSON_PRETTY_PRINT|JSON_HEX_QUOT|JSON_HEX_TAG|JSON_HEX_AMP|JSON_HEX_APOS); if (JSON_ERROR_NONE != json_last_error()) { die(json_last_error_msg()); diff --git a/examples/stream.php b/examples/stream.php index 02b7ba67..2fe8d917 100755 --- a/examples/stream.php +++ b/examples/stream.php @@ -55,7 +55,7 @@ $reader->setLimit(3); $res = $reader->fetchAssoc(['Prenom', 'Occurences', 'Sexe', 'Annee']); -var_dump($res); +var_dump(iterator_to_array($res, false)); ?>

Let's remove the string.toupper stream filter

if ($reader->isActiveStreamFilter()) {
@@ -65,7 +65,7 @@
 $reader->setLimit(3);
 $res = $reader->fetchAssoc(['Prenom', 'Occurences', 'Sexe', 'Annee']);
 
-var_dump($res);
+var_dump(iterator_to_array($res, false));isActiveStreamFilter()) { @@ -75,7 +75,7 @@ $reader->setLimit(3); $res = $reader->fetchAssoc(['Prenom', 'Occurences', 'Sexe', 'Annee']); -var_dump($res); +var_dump(iterator_to_array($res, false)); ?>

Using the Writer class

diff --git a/examples/table.php b/examples/table.php index 343569d9..6e567819 100755 --- a/examples/table.php +++ b/examples/table.php @@ -7,7 +7,7 @@ $inputCsv = Reader::createFromPath('data/prenoms.csv'); $inputCsv->setDelimiter(';'); $inputCsv->setEncodingFrom("iso-8859-15"); -$inputCsv->setLimit(30); +$inputCsv->setLimit(30); //we are limiting the convertion to the first 31 rows ?> diff --git a/examples/writing.php b/examples/writing.php index 7447175f..ebf4e9cb 100755 --- a/examples/writing.php +++ b/examples/writing.php @@ -4,34 +4,34 @@ require '../vendor/autoload.php'; -$writer = Writer::createFromFileObject(new SplTempFileObject()); //the CSV file will be created into a temporary File -$writer->setDelimiter("\t"); //the delimiter will be the tab character -$writer->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries - -$headers = ["position" , "team", "played", "goals difference", "points"]; -$writer->insertOne($headers); +$header = ["position" , "team", "played", "goals difference", "points"]; -$teams = [ +$contents = [ [1, "Chelsea", 26, 27, 57], [2, "Arsenal", 26, 22, 56], - [3, "Manchester City", 25, 41, 54], + [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); +$writer = Writer::createFromFileObject(new SplTempFileObject()); //the CSV file will be created using a temporary File +$writer->setDelimiter("\t"); //the delimiter will be the tab character +$writer->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries +$writer->setOutputBOM(Writer::BOM_UTF8); //adding the BOM sequence on output +$writer->insertOne($header); +$writer->insertAll($contents); ?> - Using the \League\Csv\Writer object + Using the Writer class -

Example 4: Using Writer object

+

Example 4: Using the Writer class

The table representation of the csv

toHTML('table-csv-data with-header');?>

The Raw CSV to be saved

diff --git a/examples/xml.php b/examples/xml.php index 3104680f..86b34c96 100755 --- a/examples/xml.php +++ b/examples/xml.php @@ -4,16 +4,17 @@ require '../vendor/autoload.php'; + //we order the result according to the number of firstname given +$func = function ($row1, $row2) { + return strcmp($row2[1], $row1[1]); +}; + $csv = Reader::createFromPath('data/prenoms.csv'); $csv->setEncodingFrom('ISO-8859-15'); -$csv->setFlags(SplFileObject::READ_AHEAD|SplFileObject::SKIP_EMPTY); $csv->setDelimiter(';'); -//since version 7.0 only 10 rows will be converted using the query options $csv->setOffset(1); $csv->setLimit(10); -$csv->addSortBy(function ($row1, $row2) { - return strcmp($row2[1], $row1[1]); //we order the result according to the number of firstname given -}); +$csv->addSortBy($func); $doc = $csv->toXML('csv', 'ligne', 'cellule'); $xml = $doc->saveXML(); header('Content-Type: application/xml; charset="utf-8"');
Part of the CSV from the 801th row with at most 25 rows
'.PHP_EOL.'', $row), ''.PHP_EOL.'', $row), '