Re: How can I insert the data into the begining of a text file
| From: | Christian Reiniger | Date: | Thu, 23 Aug 2001 09:34:32 +0000 |
| Subject: | Re: How can I insert the data into the begining of a text file | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-64068@lists.php.net to get a copy of this message | ||
On Wednesday 22 August 2001 18:14, Zenith wrote:
> I have try this but, PHP just overwrite the prevoius content, and write
> the new message into the file.
> But I want to INSERT the new message into the head of a file.
You actually have to read everything, insert the line, write everything.
file() will come in handy for that.
If you need to do this insertion stuff often you propably should use a
database (or simply append to the end instead of inserting at the
beginning of the file)
> $fp = fopen (
> $HTTP_SERVER_VARS['DOCUMENT_ROOT']."/log/debug_message.txt", "r+"
> );
Especially here it would be perfectly fine to just append to the end of
the file.
> fputs ( $fp, "\nDebug message from : $PHP_SELF at ".strftime("%T on
> %D")."\n" );
> fputs ( $fp, "$message\n\n" );
> fclose ( $fp );
>
> "Niklas lampén" <niklas.lampen@publico.fi> ?????
> news:NPEFKEPHNLKEPEOLHPKNIENPCCAA.niklas.lampen@publico.fi...
>
> > Use $fp = fopen($file, "r+");
--
Christian Reiniger
LGDC Webmaster (http://lgdc.sunsite.dk/)
Install once, run forever. Linux.