PHP code example of lianhua / supercsv

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

    

lianhua / supercsv example snippets


$csv = new \Lianhua\SuperCSV\Reader("/path/to/csv");
$csv->read(); // ["A", "B", "C", "D"]
$csv->read(); // ["E", "F", "G", "H"]

$csv = new \Lianhua\SuperCSV\Reader("/path/to/csv");
$csv->readAll(); // [["A", "B", "C", "D"], ["E", "F", "G", "H"]]

$csv = new \Lianhua\SuperCSV\Reader("/path/to/csv", ";", "'", "!");

$csv = new \Lianhua\SuperCSV\Reader("/path/to/csv");
$csv->getHeader();
$csv->read(); // ["English" => "Apple", "French" => "Pomme"]
$csv->read(); // ["English" => "Pear", "French" => "Poire"]

$csv = new \Lianhua\SuperCSV\Writer("/path/to/csv");
$csv->write(["A", "B", "C", "D"]);
$csv->write(["E", "F", "G", "H"]);

$csv = new \Lianhua\SuperCSV\Writer("/path/to/csv");
$csv->writeAll([["A", "B", "C", "D"], ["E", "F", "G", "H"]]);

$csv = new \Lianhua\SuperCSV\Writer("/path/to/csv", false);

$csv = new \Lianhua\SuperCSV\Writer("/path/to/csv", true, ";");
$csv->write(["A", "B", "C", "D"]);
$csv->write(["E", "F", "G", "H"]);

$csv = new \Lianhua\SuperCSV\Reader("/path/to/csv");
$csv->setHeader(["English", "French"]);
$csv->write(["English" => "Apple", "French" => "Pomme"]);
$csv->write(["French" => "Poire", "English" => "Pear"]);