PHP code example of cfv1000 / csv-reader

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

    

cfv1000 / csv-reader example snippets



use cfv1000\CsvReader\Reader;

$csv = new Reader('path/to/your/file.csv');

foreach ($csv as $line) {
    print_r($line);
}


use cfv1000\CsvReader\Reader;

// Semicolon-separated file
$csv = new Reader('path/to/your/semicolon_file.csv', ';');

foreach ($csv as $line) {
    print_r($line);
}


use cfv1000\CsvReader\Reader;

$csv = new Reader('path/to/your/file.csv');

$lineCount = count($csv); // This will return the total number of lines
echo "Total lines: " . $lineCount;


use cfv1000\CsvReader\Reader;

$csv = new Reader('path/to/your/file.csv');

$lineCount = count($csv); 
echo "Total lines: " . $lineCount . PHP_EOL;
// Rewind the file pointer to the beginning to start reading
$csv->rewind();

foreach ($csv as $line) {
    print_r($line);
}