You are here: Re: using fputcsv() « PHP Programming Language « IT news, forums, messages
Re: using fputcsv()

Posted by Rik Wasmus on 11/08/07 21:16

On Thu, 08 Nov 2007 17:20:35 +0100, <shenoyvikram@yahoo.com> wrote:

> 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 =3D fgetcsv($fid, 1000, ",")) !=3D=3D FALSE) {
> if (strcmp ($data[0], $var) =3D=3D 0){
> fseek ($fid,$offset_counter);
> fputcsv($fid, $data);
> $offset_counter =3D 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

RTFM:
fputcsv() formats a line (passed as a fields array) as CSV and write it =
=

(terminated by a newline) to the specified file handle.

It's because the csv line is terminated by a newline charecter. Try to =

write a single in a new file: it will contain this:
"1,2,3
"
Not:
"1,2,3"
-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация