From 8b913996bbeff055585beb6b4307b5b33082c919 Mon Sep 17 00:00:00 2001 From: Christian Schneider Date: Fri, 22 Nov 2024 16:04:18 +0100 Subject: Add (as of PHP 8.4) mandatory str_getcsv escape parameter but use newly recommended empty string to disable it instead of old default of backslash --- it_pipe.class | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/it_pipe.class b/it_pipe.class index 413a7b5..30e89e5 100644 --- a/it_pipe.class +++ b/it_pipe.class @@ -208,7 +208,7 @@ function csv($p = []) $counts = count_chars($this->lines[0]); $splitchar = $counts[ord("\t")] ? "\t" : ($counts[ord(";")] > $counts[ord(",")] ? ";" : ","); $csvhead = it::replace(['^\x{FEFF}' => ''], array_shift($this->lines)); # it::replace removes utf8 byte order mark - $schema = $p['forceschema'] ? explode(",", $p['forceschema']) : str_getcsv(trim($csvhead, "#\n "), $splitchar, '"'); # should function_exists('str_getcsv') + $schema = $p['forceschema'] ? explode(",", $p['forceschema']) : str_getcsv(trim($csvhead, "#\n "), $splitchar, '"', ''); # should function_exists('str_getcsv') foreach ($schema as $idx => $col) $schema[$idx] = it::replace(['^$' => "field$idx", '\W' => $p['fixcolnames'] ? "_" : '$0'], $col); @@ -218,7 +218,7 @@ function csv($p = []) foreach ($this->lines as $line) { - if (($cols = str_getcsv($line, $splitchar, '"')) && (count($schema) == count($cols) || $nullcols)) + if (($cols = str_getcsv($line, $splitchar, '"', '')) && (count($schema) == count($cols) || $nullcols)) $records[] = (object)array_combine($schema, $cols + $nullcols); else return (array)it::error((array)$p['it_error'] + ['title' => "csv column count mismatch: " . count($schema) . " in header vs " . count($cols) . " in row", 'body' => [$schema, $cols]]); -- cgit v1.2.3