Open Manc opened 10 years ago
Because I needed a quick and dirty solution I had to implement the CSV export myself. So I'm alright for now. If goodby/csv doesn't support force-enclosing values, I hereby suggest this as a new feature for a future version. Thanks!
:+1: for this
Hi,
u can use this approach to deal with your problem
/\ $line is an array, each value is encapsulated by double quotes **/
private function addLine($line)
{
$csv = implode(";", $line) . PHP_EOL;
file_put_contents($this->_file, $csv, FILE_APPEND);
}
As far as I know, by CSV standard you may enclose fields even if there is no real or obvious need.
In my case I'm dealing with a field for a German 5-digits postal code that may start with a zero (e.g. "01234"), but must always be interpreted as a string. Importing the CSV file with software such as Excel, the value is interpreted as number (1234) if it's not enclosed.
I tried a
CallbackCollection
and cast all values tostring
, but that didn't make any difference.I could add a whitespace to numeric values, but then the CSV data contains whitespaces, which isn't great either.
Is there an option to force enclosing a field? Or at least a better trick than adding a whitespace?