0

I have an array $email_details and it is like this :

Array
(
    [email_address] => myemailid@yahoo.com
    [mail_client_friendly_name] => Apple iPhone iOS 7
)

I am trying to put this in CSV and doing the following code :

    header("Content-type: text/csv");
    header("Content-Disposition: attachment; filename=file.csv");
    $outputBuffer = fopen("php://output", 'w');
        foreach ($email_details as $email) {
            fputcsv($outputBuffer,$email); 
        }
        fclose($outputBuffer);

I am getting the CSV file here. But when I open it in open office or any other spreadsheet , the first part of second column is displayed along with first and the rest spawned across multiple columns. When I checked the o/p it is like the second column is wrapped inside double quotes. How can I show it in a single column

Here is a screen shot

enter image description here

The Apple iPhone iOs7 should come in one column. I mean first column should be the email ID and second column is the client name.

Happy Coder
  • 4,255
  • 13
  • 75
  • 152
  • Are you missing quotes around "Apple iPhone iOS 7" in `$email_details`? What exactly is `$litmus_data`? – pLiKT Dec 23 '13 at 06:42
  • It is the same $email_data array. I corrected the mistake. The thing is that I don't have quotes there in DB for the value and so there is no quotes in array also. – Happy Coder Dec 23 '13 at 06:45
  • 1
    Check your csv viewer (excel?). Maybe it is separating your file with space instead of comma. – Orifjon Dec 23 '13 at 07:01

0 Answers0