MattyUK
05-30-2011, 07:01 PM
How can I temporarily set relevent line terminators for fputscsv and fgetcsv?
CR = \r = Carriage Return = Chr(13)
LF = \n = Line Feed, NewLine = Chr(10)
Windows uses CRLF for newlines and LF mid line for multi-lines within CSV feilds (ALT+ENTER in Excel).
Linux uses LF for newlines.
I want LF's supported in CSV fields, and CRLF for line terminators.
My Linux server wants to use LF's for line terminators.
I need to use fputscsv and fgetcsv to read arrays to csv and back again. The stored CSV will eventually be imported into Excel.
As you can imagine this competing requirement for LF's doesn't go well and excel imports go badly.
So to summarize I have PHP array data from an explode operation and other sources that contains LF's and I need to store it in CSV (or other suitable file container) using CRLF's for line terminators and retain compatiblity with using fputscsv and fgetcsv.
I'm struggling with how to marry this conflicting requirement over LF's and can't figure out how to set the relevent line terminators for fputscsv and fgetcsv.
I'm hoping for a full example or pointers to a tutorial that covers this mismatch. Any advice?
What is everyone else doing?
What other problems with this approach are likely?
Is there a better route forward that can support the above requirements, whilst still using a file container and not a MySQL database?
Should I write my own fputscsv and fgetcsv functions to cover the requirement or use PEAR Datagrids?
Yours hopefully
Matty
CR = \r = Carriage Return = Chr(13)
LF = \n = Line Feed, NewLine = Chr(10)
Windows uses CRLF for newlines and LF mid line for multi-lines within CSV feilds (ALT+ENTER in Excel).
Linux uses LF for newlines.
I want LF's supported in CSV fields, and CRLF for line terminators.
My Linux server wants to use LF's for line terminators.
I need to use fputscsv and fgetcsv to read arrays to csv and back again. The stored CSV will eventually be imported into Excel.
As you can imagine this competing requirement for LF's doesn't go well and excel imports go badly.
So to summarize I have PHP array data from an explode operation and other sources that contains LF's and I need to store it in CSV (or other suitable file container) using CRLF's for line terminators and retain compatiblity with using fputscsv and fgetcsv.
I'm struggling with how to marry this conflicting requirement over LF's and can't figure out how to set the relevent line terminators for fputscsv and fgetcsv.
I'm hoping for a full example or pointers to a tutorial that covers this mismatch. Any advice?
What is everyone else doing?
What other problems with this approach are likely?
Is there a better route forward that can support the above requirements, whilst still using a file container and not a MySQL database?
Should I write my own fputscsv and fgetcsv functions to cover the requirement or use PEAR Datagrids?
Yours hopefully
Matty