1. Go to this page and download the library: Download belguinan/csv-simple-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/ */
belguinan / csv-simple-reader example snippets
use Belguinan\CsvExporter;
// Initialize
$csv = new CsvExporter();
// Read CSV file
foreach ($csv->readFrom('path/to/file.csv') as $row) {
var_dump($row);
}
$csv = new CsvExporter();
// Read file line by line (memory efficient)
foreach ($csv->readFrom('input.csv') as $row) {
// $row is an array containing the CSV columns
var_dump($row);
}
// Your data as array
$data = array(
array('John', 'Doe', '[email protected]'),
array('Jane', 'Smith', '[email protected]')
);
// Optional headers
$headers = array('First Name', 'Last Name', 'Email');
// Create CSV exporter
$csv = new CsvExporter($data, $headers);
// Process and save
$csv->process()->save('output.csv');
// Create and force download
$csv = new CsvExporter($data, $headers);
$csv->process()->download('users-export');
// Process, download, and save in one go
$csv->process()
->download('export-file')
->save('backup/export.csv');