Reputation: 67
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+ ...
Upvotes: 0
Views: 437
Reputation: 722
change the separator to ';'; i got same issues before because you are excel to read it .
Upvotes: 1