|
4 | 4 |
|
5 | 5 | require '../vendor/autoload.php'; |
6 | 6 |
|
7 | | -$writer = Writer::createFromFileObject(new SplTempFileObject()); //the CSV file will be created into a temporary File |
8 | | -$writer->setDelimiter("\t"); //the delimiter will be the tab character |
9 | | -$writer->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries |
10 | | - |
11 | | -$headers = ["position" , "team", "played", "goals difference", "points"]; |
12 | | -$writer->insertOne($headers); |
| 7 | +$header = ["position" , "team", "played", "goals difference", "points"]; |
13 | 8 |
|
14 | | -$teams = [ |
| 9 | +$contents = [ |
15 | 10 | [1, "Chelsea", 26, 27, 57], |
16 | 11 | [2, "Arsenal", 26, 22, 56], |
17 | | - [3, "Manchester City", 25, 41, 54], |
| 12 | + [3, "Manchester City", 25, 41, 54,], |
18 | 13 | [4, "Liverpool", 26, 34, 53], |
19 | 14 | [5, "Tottenham", 26, 4, 50], |
20 | 15 | [6, "Everton", 25, 11, 45], |
21 | 16 | [7, "Manchester United", 26, 10, 42], |
22 | 17 | ]; |
23 | 18 |
|
24 | | -$writer->insertAll($teams); |
| 19 | +$writer = Writer::createFromFileObject(new SplTempFileObject()); //the CSV file will be created using a temporary File |
| 20 | +$writer->setDelimiter("\t"); //the delimiter will be the tab character |
| 21 | +$writer->setNewline("\r\n"); //use windows line endings for compatibility with some csv libraries |
| 22 | +$writer->setOutputBOM(Writer::BOM_UTF8); //adding the BOM sequence on output |
| 23 | +$writer->insertOne($header); |
| 24 | +$writer->insertAll($contents); |
25 | 25 | ?> |
26 | 26 | <!doctype html> |
27 | 27 | <html lang="fr"> |
28 | 28 | <head> |
29 | 29 | <meta charset="utf-8"> |
30 | | - <title>Using the \League\Csv\Writer object</title> |
| 30 | + <title>Using the Writer class</title> |
31 | 31 | <link rel="stylesheet" href="example.css"> |
32 | 32 | </head> |
33 | 33 | <body> |
34 | | -<h1>Example 4: Using Writer object</h1> |
| 34 | +<h1>Example 4: Using the Writer class</h1> |
35 | 35 | <h3>The table representation of the csv</h3> |
36 | 36 | <?=$writer->toHTML('table-csv-data with-header');?> |
37 | 37 | <h3>The Raw CSV to be saved</h3> |
|
0 commit comments