Using PHP to extract data from SQL and then creating a .csv file on the server for emailing/download by way of fputcsv. All works well other than trying to get a new line within a field in Excel (2003).
I get Product1Product2Product3 in the cell when I need
Product1
Product2
Product3
I have tried single quotes, double quotes, CRs, LFs and I am rapidly disapearing up my own backside.
So the question is – what character do I need to get into the CSV file to achieve this?
It has to work in Excel
[Solution] – the problem lay somewhere in passing the \r\n to Excel through the PHP fputcsv – I was unable to achieve this in any sort of fashion (plenty of appending the desired \r\n to my actual cell data e.g. Product1\r\n)
The suggestion to use $lfcr = chr(10) . chr(13); worked first time around. I guess this was more of a PHP rather than an Excel question – thanks to all resonses.
This is more of an excel rather than a php question. What you put into the csv file needs to be understood by excel which is why \r\n will not work.
Use this
Then append
$lfcrto the end of each line.