Site Tools


Hotfix release available: 2025-05-14b "Librarian". upgrade now! [56.2] (what's this?)
Hotfix release available: 2025-05-14a "Librarian". upgrade now! [56.1] (what's this?)
New release available: 2025-05-14 "Librarian". upgrade now! [56] (what's this?)
prog:php:samples:csv_parse

This is an old revision of the document!


One liner to get a CSV file into 2-dimentional array (NB! Only works if “,” is the separator!!!):

$csv = array_map('str_getcsv', file('data.csv'));

Work with each line in a CSV file:

$handle = fopen("data_sample_5_sec.csv", "r");
 
$is_first_row_header = true;
 
for ($i = 0; $row = fgetcsv($handle ); ++$i) {
    if ($is_first_row_header AND $i == 0) {
        $headers = $row;
        continue;
    }
 
    // Do something with $row array
    $row[''];
}
fclose($handle);
prog/php/samples/csv_parse.1651070684.txt.gz · Last modified: 2022/04/27 17:44 by rene