Page 1 of 1

Getting fputcsv to write a number as string for Excel

Posted: Fri Mar 10, 2006 9:17 pm
by anjanesh
Hi

I have an $row that is an array. Im writing to a csv file which I opened in Excel. Problem is, that Excel is treating the Phone column as a number. So I did $row['Phone'] = '"'.$row['Phone'].'"';

Code: Select all

$row['Phone'] = '"'.$row['Phone'].'"';
fputcsv ($h, $row)."\n";
But now fputcsv is entering it as

Code: Select all

value5,"""56565656""",value7
so in Excel it shows up as

Code: Select all

value5,"56565656",value7
But I want is

Code: Select all

value5,"56565656",value7
so that Excel will treat it as a string and not a string with double-quotes.

How to I 'tell' fgetcsv not enter 3 quotes but only 1 ?

Thanks