Re: writing to files

From: Date: Wed, 27 Sep 2000 05:38:40 +0000
Subject: Re: writing to files
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-17721@lists.php.net to get a copy of this message
On Wed, 27 Sep 2000, Generic Player wrote: > > Hi > > Here is what I am doing. I wrote a script to update news.txt and copy what was in it to an > aold archive.txt. Problem is I want to have the archived news displayed with the most recent > article at the top. Any way to do that without storing news items in a database or seperate .txt > files for each news item? > > Thanks in advance > Generic Player > Presumably you are opening the file in append mode and tacking the new stuff on the end? Try something like: Read the file into an array with file (Make a copy of the file in case something goes wrong?) Open the file in write mode (truncates the file) Write the new data to the file Write the array back to the file This will put your new stuff at the beginning of the file. -- David Robley | WEBMASTER & Mail List Admin RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/ AusEinet | http://auseinet.flinders.edu.au/ Flinders University, ADELAIDE, SOUTH AUSTRALIA

« previous php.general (#17721) next »