1

I am using FastExcel to generate .csv templates, but it downloads it with LF instead of CRLF for the line breaks, so whenever I edit the files on Windows, and upload the file back to the server, the .csv formatting is messed up.

I'm not sure if it downloads it using LF automatically because the server is Linux. (So maybe if the server was on Windows it would have downloaded it with CRLF?)

How can I fix that?

pileup
  • 1
  • 2
  • 18
  • 45
  • If _"and upload the file back to the server"_ means FTP, then simply set the transfer mode to ASCII ...? – CBroe Jan 19 '22 at 11:07
  • you can always do a `shell_exec('dos2unix ')` to convert CRLF to LF endings after it's been uploaded back. (assuming dos2unix is installed) – apokryfos Jan 19 '22 at 11:12
  • FastExcel is a wrapper for [Spout](https://github.com/box/spout), which is a wrapper for [fputcsv()](https://www.php.net/fputcsv). Unfortunately, the optional `$eol` argument is left with the default value `\n` ([code](https://github.com/box/spout/blob/master/src/Spout/Common/Helper/GlobalFunctionsHelper.php#L98)). That means you'd need to extend some classes, if it's possible to make the libraries work that way (I don't really know). – Álvaro González Jan 19 '22 at 13:14
  • Thanks guys, I used another parsing library that has an option to choose how to parse new lines, either `\n` or `\r\n`, so I used `\n` and it's ok now. I wonder if it's using `dos2unix` to do that – pileup Jan 19 '22 at 13:54

0 Answers0