1

I have the following code :

        header('Content-Encoding: UTF-8');
        header("Content-Type:application/csv;charset=UTF-8");
        header('Content-Disposition: attachement; filename="' . $sFileName . '";');
        header("Pragma: no-cache");
        header("Expires: 0");
        header("Refresh:0");
        echo "\xEF\xBB\xBF";
        $output = fopen('php://output', 'w');
        fwrite($output, "sep=;\n");
        fputcsv($output, array('1','2','3'), ";");
        foreach ($aExport as $value) {
            fputcsv($output, $value, ";");
        }
        fpassthru($output);
        fclose($output);
        exit;

For example if I have multiples 0000 witch need to be put in the first column it truncate the rest and it put only one zero. I dont'n understand why. Can you help me please ? Thx in advance

Harea Costicla
  • 797
  • 3
  • 9
  • 20
  • Don't use `fpassthru($output);`.... what do you think that does when $output is already php://output? – Mark Baker Mar 11 '16 at 14:08
  • 1
    `if I have multiples 0000 witch need to be put in the first column it truncate the rest and it put only one zero. I dont'n understand why` Because that's what MS Excel does with CSV files.... look at the "raw" CSV in a text editor, and you'll see that it's still '0000' - [Demo](https://3v4l.org/TW31U) – Mark Baker Mar 11 '16 at 14:09
  • Possible duplicate of [fputcsv display leading zeros](http://stackoverflow.com/questions/11078531/fputcsv-display-leading-zeros) – Sébastien Mar 11 '16 at 14:10

0 Answers0