cooperino's avatar

How to download CSV file with CRLF and not LF?

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 file on Windows and upload the file back to the server, the .csv formatting is messed up.

Edit: Is it because the server is run on Linux machine so it does that automatically, so if the server was on Windows it would have generated it with CRLF? But still, what should I do to make it work properly?

How can I fix that?

0 likes
3 replies
aschmelyun's avatar

@cooperino It might be because of the server, but I'm not 100% sure. However, the following code should normalize the line breaks, just pass your content through it via the $content variable:

$content = str_replace(array("\r\n", "\r", "\n"), "\n", $content);
cooperino's avatar

@Doris69 @aschmelyun I found the reason, it's because a JS parsing library is used to upload the file back to the server and it is using \r\n instead of \n. So you were close @aschmelyun

1 like

Please or to participate in this conversation.