Merge pull request #162 from parsecsv/add-save-example

Added example for writing CSV files to better document heading property
This commit is contained in:
susgo
2019-02-02 20:40:45 +01:00
committed by GitHub
2 changed files with 30 additions and 1 deletions

View File

@@ -0,0 +1,27 @@
<?php
# include parseCSV class.
require __DIR__ . '/../vendor/autoload.php';
use ParseCsv\Csv;
# Create new parseCSV object.
$csv = new Csv();
# When saving, don't write the header row:
$csv->heading = false;
# Specify which columns to write, and in which order.
# We won't output the 'Awesome' column this time.
$csv->titles = ['Age', 'Name'];
# Data to write:
$csv->data = [
0 => ['Name' => 'Anne', 'Age' => 45, 'Awesome' => true],
1 => ['Name' => 'John', 'Age' => 44, 'Awesome' => false],
];
# Then we save the file to the file system:
$csv->save('people.csv');

View File

@@ -59,7 +59,9 @@ class ConstructTest extends TestCase {
/** @noinspection PhpIncludeInspection */ /** @noinspection PhpIncludeInspection */
require $script_file; require $script_file;
$ob_get_clean = ob_get_clean(); $ob_get_clean = ob_get_clean();
if ($script_file != 'download.php') { $verb = strtok($script_file, '_.');
if (!in_array($verb, ['download', 'save'], true)) {
$this->assertContains('<td>', $ob_get_clean); $this->assertContains('<td>', $ob_get_clean);
} }
} }