PHP code example of rakdar / reactphp-csv

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

    

rakdar / reactphp-csv example snippets


$loop = React\EventLoop\Factory::create();

$inputFd = fopen('country-codes.csv', 'r');
$input = new Rakdar\React\Csv\Reader(
    new React\Stream\ReadableResourceStream($inputFd, $loop)
);

$input->on('data', function ($field) {
    echo $field[10] . PHP_EOL;
});

$loop->run();

$loop = React\EventLoop\Factory::create();

$outputFp = fopen('testfile.csv', 'w');
$output = new Rakdar\React\Csv\Writer(
    new React\Stream\WritableResourceStream($outputFp, $loop)
);
$output->write(['Header 1', 'Header 2', 'Header 3']);
$output->write(['Col 1.1', 'Col 1.2', 'Col 1.3']);
$output->write(['Col 2.1', 'Col 2.2', 'Col 2.3']);

$output->close();

$loop->run();