PHP csv function fputcsv -


i telling function "fputcsv" buggy ! why saying ? created csv file 4 lines

l1data1;l1data2;l1data3;l1data4 l2data1;l2data2;l2data3;l2data4 l3data1;l3data2;l3data3;l3data4 l4data1;l4data2;l4data3;l4data4 

ok simple copy file file using fgetcsv , fputcsv 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 reason leaving double quotes in third column no obvious reason.

now old ways :

while ($data=fgets($handle)){    fputs($temporaryfile, $data); } 

output expected :

l1data1;l1data2;l1data3;l1data4 l2data1;l2data2;l2data3;l2data4 l3data1;l3data2;l3data3;l3data4 l4data1;l4data2;l4data3;l4data4 

explain !

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 header rest 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 length parameter:

must greater longest line (in characters) found in csv file (allowing trailing line-end characters). became optional in php 5. omitting parameter (or setting 0 in php 5.0.4 , later) maximum line length not limited, slower.

i can't tell sure looks code you're omitting handle which, depending on version may legal, seems ambiguous also? try adding 0 parameter there perhaps?


Comments