0

i try to download a csv file, but when i download it, my data are only in one column.

I have

[1,2,3,4,5] [] [] [] []

And i need

[1] [2] [3] [4] [5]

My code :

function to_csv($tab){
$Allarray=array();
foreach ($tab as $tableau){
    $Allarray[]=$tableau;
}

$separateur = "\t";
$entete = array('firstname', 'name', 'mail', 'rate','review','review_date','order_ref', 'oder_date', 'source');


$file = implode($separateur, $entete) . "\r\n";

foreach ($Allarray as $ligne) {
    $file .= implode($separateur, $ligne) . "\r\n";
}

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=ebay_export_'.date("dmYHis").'.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
print chr(239) . chr(187) . chr(191) .($file);
exit;

}

edit : My values for tab is the data foreach column :

 array (size=36)
  0 => 
    array (size=9)
      'firstname' => 
        object(SimpleXMLElement)[9]
          public 0 => string 'mywifemademe' (length=12)
      'name' => string ' ' (length=1)
      'mail' => string '[email protected]' (length=23)
      'rate' => int 5
      'review' => 
        object(SimpleXMLElement)[12]
          public 0 => string 'WONDERFUL-FAST PAYMENT-GREAT COMMUNICATION-FIRST CLASS! A+A+' (length=60)
      'review_date' => 
        object(SimpleXMLElement)[13]
          public 0 => string '2002-06-08T18:29:31.000Z' (length=24)
      'order_ref' => string '1539157020_EBAY_2018-03-13 15:21:40_0' (length=37)
      'order_date' => 
        object(SimpleXMLElement)[19]
          public 0 => string '2002-06-08T18:29:31.000Z' (length=24)
      'source' => string '12' (length=2)
  1 => 
  ...

But when i download the .csv, in my excel, all this data are in column "A" :

    firstname   name    mail    rate    review  review_date order_ref order_date source

mywifemademe [email protected] WONDERFUL-FAST PAYMENT-GREAT COMMUNICATION-FIRST CLASS! A+A+ ...
5
  • And what are the contents of the file? Commented Mar 13, 2018 at 14:03
  • “I have [1,2,3,4,5] [] [] [] []” - is that the actual file content, or what you see after you opened this in Excel? Commented Mar 13, 2018 at 14:04
  • And what is the value of $tab? Per @FedericoklezCulloca we can guess tab, but you haven't shared that with us, so it's just a guess... Commented Mar 13, 2018 at 14:05
  • 1
    Are you watching your CSV file in Excel? Excel uses a semicolon as a separator by default. If you use another one (in your example \t) you need to tell Excel by using the Data >> Text to columns function Commented Mar 13, 2018 at 14:08
  • i have edit my post for more explain Commented Mar 13, 2018 at 14:25

1 Answer 1

1

change the separator to ';'; i got same issues before because you are excel to read it .

Sign up to request clarification or add additional context in comments.

1 Comment

Not all heroes wear capes 🙌

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.