using fputcsv()



New to PHP
I am running a loop searching a csv file. When I have a match I am
trying to replace the matched line with new data.
However everytime I do the replace, there is an empty line in the
file.
- Does fputcsv insert or replace? ( I am using fseek to move to the
appropriate location in the file to write)

while( ($data = fgetcsv($fid, 1000, ",")) !== FALSE) {
if (strcmp ($data[0], $var) == 0){
fseek ($fid,$offset_counter);
fputcsv($fid, $data);
$offset_counter = ftell ($fid);
}

my file starts like this
11,11,11,11
22,22,22,22
33,33,33,33

Should end up like this
11,11,11,11
33,22,22,22
33,33,33,33

but instead looks like this
11,11,11,11
33,22,22,22

33,33,33,33

.



Relevant Pages

  • Re: using fputcsv()
    ... I am trying to search through a csv file. ... to replace it using the fputcsv function. ... I am using fseek to move file ... you can read them in one line at a time and write them out to a temporary file. ...
    (comp.lang.php)
  • Re: PHP Read Text File
    ... Open the file, fseek() to the end, read 4Kb chunks, then strrchr() to find ... Proudly running Debian Linux with 2.6.24-1-amd64 kernel, KDE 3.5.9, and PHP ...
    (comp.lang.php)
  • using fputcsv()
    ... I am trying to search through a csv file. ... when I match a string I want ... to replace it using the fputcsv function. ... I am using fseek to move file ...
    (comp.lang.php)