Tobin Thomas Tobin Thomas - 23 days ago 8
PHP Question

how to put a space after decimal value in csv using fputcsv?

enter image description here

This is the code i have used to write data into csv file.
Everything is working fine except decimal values!

$row[] = '14.31 ';
fputcsv($fp, $row, ',', '"');


i have a space after .31
"14.31 "
so length should be
"6"
and now i am getting
"5"
.

how to include this space in the cell?

Answer Source

Assign the value to a variable and convert to string Eg : $test ='14. 31 '; $row[] =(string) $test;

Or use double quotes Eg: $test = "14.31" ;