PHP code example of morrislaptop / php-parsecsv

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

    

morrislaptop / php-parsecsv example snippets


$csv = new parseCSV('data.csv');
print_r($csv->data);

$csv = new parseCSV();
$csv->encoding('UTF-16', 'UTF-8');
$csv->delimiter = "\t";
$csv->parse('data.tsv');
print_r($csv->data);

$csv = new parseCSV();
$csv->auto('data.csv');
print_r($csv->data);

$csv = new parseCSV();
$csv->sort_by = 'id';
$csv->parse('data.csv');
# "4" is the value of the "id" column of the CSV row
$csv->data[4] = array('firstname' => 'John', 'lastname' => 'Doe', 'email' => '[email protected]');
$csv->save();

$csv = new parseCSV();
$csv->save('data.csv', array('1986', 'Home', 'Nowhere', ''), true);

$csv = new parseCSV();
$csv->output('movies.csv', $array, array('field 1', 'field 2'), ',');