Re: Append to the beginning of a file...

From: Date: Thu, 21 Mar 2002 18:47:42 +0000
Subject: Re: Append to the beginning of a file...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-89573@lists.php.net to get a copy of this message
I guess I should do that. I need the plain file because is just a log of users registering in a Club, in a csv format. Using a database is just too much and not intended for this page... even when I would prefer using mysql. At least, I can handle that rather than the fopen and fwrite !. I could append but then I need to read the first 8 chars of the last line I appended... neither something I know how to do. If they were fixed I could... maybe I can fill it with blank chars the line until a given size ? Thanxs everyone for your replies. "Miguel Cruz" <mnc@stoic.net> escribió en el mensaje news:Pine.LNX.4.44.0203211114530.5131-100000@stoic.net... > On Thu, 21 Mar 2002, Mauricio Sthandier wrote: > > I guess thist must be really silly... but how can I append text to the > > beginning of a file ??? > > I've been trying since a while... but all I get is overwriting !. > > Open a temporary file, write your new data to it, copy the old file on to > the end of it, remove the old file, rename the temporary file with the old > file's name. > > Obviously this is not very efficient. Explore whether you really need to > prepend. Perhaps you can append and then read the file backwards a la tac? > Or perhaps a database is more useful. Or multiple files. > > miguel >

« previous php.general (#89573) next »