mirror of
https://github.com/getgrav/grav.git
synced 2026-02-20 21:48:04 +01:00
CSVFormatter null char support
This commit is contained in:
@@ -79,6 +79,9 @@ class CsvFormatter extends AbstractFormatter
|
||||
// Get the field names
|
||||
$header = str_getcsv(array_shift($lines), $delimiter);
|
||||
|
||||
// Allow for replacing a null string with null/empty value
|
||||
$null_replace = $this->getConfig('null');
|
||||
|
||||
// Get the data
|
||||
$list = [];
|
||||
$line = null;
|
||||
@@ -86,6 +89,13 @@ class CsvFormatter extends AbstractFormatter
|
||||
foreach ($lines as $line) {
|
||||
if (!empty($line)) {
|
||||
$csv_line = str_getcsv($line, $delimiter);
|
||||
|
||||
if ($null_replace) {
|
||||
array_walk($csv_line, function(&$el) use ($null_replace) {
|
||||
$el = str_replace($null_replace, null, $el);
|
||||
});
|
||||
}
|
||||
|
||||
$list[] = array_combine($header, $csv_line);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user