Re: Append to the beginning of a file...
| From: | Chris Hewitt | Date: | Fri, 22 Mar 2002 11:19:21 +0000 |
| Subject: | Re: Append to the beginning of a file... | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-89660@lists.php.net to get a copy of this message | ||
Mauricio,
If you are on a *nix computer, you could append to the end of the file, close it and then do a "tail -n1" which will give you just the last line in the file.
HTH.
Regards
Chris
Mauricio Sthandier wrote:
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