PHP code example of tomaj / csv-processor

1. Go to this page and download the library: Download tomaj/csv-processor 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/ */

    

tomaj / csv-processor example snippets


use Tomaj\CsvProcessor\CsvExtractor;
use Tomaj\CsvProcessor\DataProcessor;
use Tomaj\CsvProcessor\Converters\EncodingConverter;
use Tomaj\CsvProcessor\Processors\PassField;
use Tomaj\CsvProcessor\Processors\RemoveField;
use Tomaj\CsvProcessor\Line;

$csvExtractor = new CsvExtractor('cesta_k_suboru_.csv', ';');
$csvExtractor->addConverter(new EncodingConverter('WINDOWS-1250', 'UTF-8')); // mozme nastavit konverziu ak treba
$data = $csvExtractor->loadData();

$processor = new DataProcessor($output);
$processor->addProcessor(new PassField('field_name', 'name')); // field 'file_name' z csvcka sa do vystupu dostane ako field 'name'
$processor->addProcessor(new RemoveField('field_ktory_sa_zmaze'));
$processor->processData($data, function(Line $line, $pid)) {
	// tu je mozne naimlementovat logiku co sa ma stat s $line kde su spracovane data
});