So I have a line that I want to do a fputcsv on that has some integers (that I need to be treated as strings but they are numbers). These integers have leading zeroes that get cut off when I do the fputcsv but I don't want that to occur, is there any way around this? I tried just typcasting as (string) and putting my variable in quotations but the only way I have found so far is to just put quotes around the entire number which leads the quotation marks to be shown in the csv file when I open it up in excel, which I don't want to occur. Does anyone know of a way to get this to work? I think the fputcsv is just automatically assigning this variable a type for some reason and making it a integer or something...
EDIT Example Text:
What I fputcsv:
02305109
What I get in the csv file opened in excel:
2305109
but the leading zero is still there when I just use vi to open said csv file. Really strange.
I had the same problem for long numbers which I wanted as a string. Wrap it in single quotes and make it evaluable.
'="' . $yourNumber . '"'
Try prepending (or appending) your leading-zero integers with a null character.
$csv[0] = 02392398."\0";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With