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
=$writer->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"');