RE: [PHP] writing to files
| From: | Jason Murray | Date: | Wed, 27 Sep 2000 06:49:20 +0000 |
| Subject: | RE: [PHP] writing to files | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-17710@lists.php.net to get a copy of this message | ||
> 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?
Okay:
- news.txt contains the current news.
- $newnews contains the new news.
- temp.txt we'll create as an intermediate step.
1. Write $newnews to a temp.txt.
2. Append news.txt to the end of temp.txt (you could use basic
unix commands to do this, ie 'cat news.txt >> newfile', or
you could open both files in PHP and copy the contents line
by line). Appending means we add it to the end of the file.
3. Copy temp.txt to news.txt.
4. Unlink() temp.txt.
Jason
(who didn't feel like coding it, sorry)