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
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| prog:php:samples:csv_parse [2022/03/15 13:10] – rene | prog:php:samples:csv_parse [2023/11/10 16:01] (current) – rene | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | One liner to get a CSV file into 2-dimentional array: | + | One liner to get a CSV file into 2-dimentional array |
| + | NB! Only works if "," | ||
| + | NB! Does not work if CSV cells have line breaks in them!!! | ||
| <code php> | <code php> | ||
| $csv = array_map(' | $csv = array_map(' | ||
| Line 11: | Line 13: | ||
| $is_first_row_header = true; | $is_first_row_header = true; | ||
| - | for ($i = 0; $row = fgetcsv($handle ); ++$i) { | + | for ($i = 0; $row = fgetcsv($handle, null, ";" |
| if ($is_first_row_header AND $i == 0) { | if ($is_first_row_header AND $i == 0) { | ||
| $headers = $row; | $headers = $row; | ||
| + | continue; | ||
| } | } | ||
prog/php/samples/csv_parse.1647342629.txt.gz · Last modified: 2022/03/15 13:10 by rene
