2

I'm doing function to export CSV file in PHP. but when i do an export, i need to add information about total in number_format().. but display is wrong.

Here is my code

header('Content-Type: text/csv; charset=utf-8');  
header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
header('Content-Disposition: attachment; filename=' . $fileName ); 
header("Content-Transfer-Encoding: binary");
header('Pragma: no-cache');
header('Expires: 0');

$file = fopen("report.csv", "w");  

fwrite($file, "Generate Report \r\n"); 
fwrite($file, "Total Sales, ".number_format($total)."\r\n");
fwrite($file, " "."\r\n");

the result is this

enter image description here

and that is wrong.

How do i can display the correct format number like "5,485" or maybe "5,485.00" in 1 cell on CSV file?

please help

Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
ferdinand
  • 325
  • 2
  • 14

1 Answers1

1
fwrite(resource $handle, string $string, int $length = ?): 

fwrite($file, "Total Sales, \"".number_format($total)."\"\r\n");

int fwrite() writes the contents of string to the file stream pointed to by handle.

Return Values fwrite() returns the number of bytes written, or false on error.

Sarthak Raval
  • 1,001
  • 1
  • 10
  • 23