PHP code example of plumphp / plum-csv

1. Go to this page and download the library: Download plumphp/plum-csv library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

plumphp / plum-csv example snippets


use Plum\PlumCsv\CsvReader;

$reader = new CsvReader('countries.csv');

$reader = new CsvReader('countries.csv`, ',', '"');

use Plum\Plum\Converter\HeaderConverter;
use Plum\Plum\Filter\SkipFirstFilter;

$workflow = new Workflow();
$workflow->addConverter(new HeaderConverter());
$workflow->addFilter(new SkipFirstFilter(1));
$reader = new CsvReader('countries.csv`, ',', '"');

use Plum\PlumCsv\CsvWriter;

$writer = new CsvWriter('foobar.csv', ',', '"');
$writer->prepare();
$writer->writeItem(['value 1', 'value 2', 'value 3');
$writer->finish();

$writer = new CsvWriter('foobar.csv');
$writer->setHeader(['column 1', 'column 2', 'column 3']);
$writer->prepare();

$writer = new CsvWriter('foobar.csv');
$writer->autoDetectHeader(); // Must be called before the first `writeItem()`

use Plum\PlumCsv\CsvWriter;
use League\Csv\Writer;

$csv = Writer::createFromFileObject(new SplFileObject('countries.csv', 'w'));
$csv->setNullHandlingMode(Writer::NULL_AS_EMPTY);
$writer = new CsvWriter($csv);