I am telling you this function "fputcsv" is buggy ! Why am i saying this ? I created a csv file with say 4 lines
l1data1;l1data2;l1data3;l1data4
l2data1;l2data2;l2data3;l2data4
l3data1;l3data2;l3data3;l3data4
l4data1;l4data2;l4data3;l4data4
ok now i simple copy this file into another file using fgetcsv and fputcsv like the following :
$handle = fopen($nameFile, "r") or die("Cannot open file: ".$nameFile);
$temporaryFile = fopen($nameTempFile, "w") or die("Cannot open file: ".$nameTempFile);
while (($data = fgetcsv($handle,"", ";")) !== false) {
fputcsv($temporaryFile, $data,";");
}
fclose($temporaryFile);
fclose($handle);
output file :
l1data1;l1data2;l1data3;l1data4
l2data1;l2data2;"l2data3";l2data4
l3data1;l3data2;"l3data3";l3data4
l4data1;l4data2;"l4data3";l4data4
for some reason it is leaving double quotes in my third column for no obvious reason.
Now i do it with some old ways :
while ($data=fgets($handle)){
fputs($temporaryFile, $data);
}
Output is like expected :
l1data1;l1data2;l1data3;l1data4
l2data1;l2data2;l2data3;l2data4
l3data1;l3data2;l3data3;l3data4
l4data1;l4data2;l4data3;l4data4
Explain this !
EDIT :
CodeOffreArtemis;CodeOffre42C;CodeOffreSagic;ServiceType;Rate;TypeInterface;Techno;Libelles;CodeOffreCristal
G8R1_ACAB;ABE;;ACA;18;Eth;A;ACo Max2;test
G8R1_ACAC;ABE;ACABUS;ACA;18;Eth;A;ACo 20MMax;
G8R1_ACAD;AKE;ACAD;ACA;2MMAX;Eth;A;ACo 2MMax;
G8R1_ACANBA;WAB;;ACA;18;Eth;A;DSL Access Max2 ACA Nu ligne active;X201
G8R1_ACANBC;WAB;;ACA;18;Eth;A;DSL Access Max2 ACA Nu sur pré-câblée;X201
G8R1_ACANBI;WAB;;ACA;18;Eth;A;DSL Access Max2 ACA Nu ligne inactive;X201
G8R1_ACANBPORA;QAB;;ACA;18;Eth;A;DSL Access Max2 ACA Nu avec portabilité L active;X201
G8R1_ACANBR;WAB;;ACA;18;Eth;A;DSL Access Max2 ACA Nu Nd de routage;X201
G8R1_ACANCA;WAB;ACANB;ACA;18;Eth;A;DSL Access 20MMax ACA Nu ligne active;X201
first line is the header rest are the data.
fgetcsv($handle,"", ";");
Looking here: http://www.php.net/manual/en/function.fgetcsv.php
array fgetcsv ( resource $handle [, int $length = 0 [, string $delimiter = ',' [, string $enclosure = '"' [, string $escape = '\\' ]]]] )
About that Length parameter:
Must be greater than the longest line (in characters) to be found in the CSV file (allowing for trailing line-end characters). It became optional in PHP 5. Omitting this parameter (or setting it to 0 in PHP 5.0.4 and later) the maximum line length is not limited, which is slightly slower.
I can't tell for sure but it looks from the code like you're just omitting the handle which, depending on version may be legal, but seems like it could be ambiguous also? Try adding a 0 parameter there perhaps?