PHP code example of 8ctopus / nano-csv

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

    

8ctopus / nano-csv example snippets


use Oct8pus\CSV\CSV;

__ .'/samples/ascii-mac-header.csv');

echo $csv
    ->autoDetect() . PHP_EOL;

while ($row = $csv->readNextRow()) {
    echo implode(', ', $row) . PHP_EOL;
}

$csv = new CSV(__DIR__ .'/samples/ascii-mac-header.csv');

$csv
    ->autoDetect()
    // convert string to number
    ->setConvertNumbers(true)
    // return associative array
    ->setAssociativeArray(true);

$average = 0;

while ($row = $csv->readNextRow()) {
    $average += $row['Average'];
}

echo "Average from May to Dec: {$average}" . PHP_EOL;

use Oct8pus\CSV\XLSX;

$xls = new XLSX(__DIR__ .'/samples/test.xlsx');

echo $xls
    ->autoDetect() . PHP_EOL;

while ($row = $xls->readNextRow()) {
    echo implode(', ', $row) . PHP_EOL;
}