hey there - 

i've been going crazy trying to figure out how to add news items to the top
of an already existing txt file containng previous news posts. While I'd
love to change the system so everything is database-driven (as most of the
rest of the site is), this news area has so much news posts that it would
take forever to convert the info the database.

SO... i want to just create a simple script that adds text to the beginning
of an existing text file, without overwriting any previous text in the file.
The manual and php site refer to using the fopen function with the r+ option
- which i've done, BUT some if the text still gets overwritten with the new

here's what I'm using:


$today = getdate();
$month = $today[month];
$mday = $today[mday];
$year = $today[year];

if ($fp = fopen("/home/foo/www/whats_new/whats_new2.txt", "r+")) {

    fwrite($fp, "this is the new line of text I want to add to the top of
the page"); 

    print "success!";


else {

print "Could not open What\'s New file for updating.";



What happens is that the line does get written to the top of the page but it
overwrites or deletes some of the existing text. Even though the r+ option
is supposed to put the pointer at the beginning of the file and add to it as
opposed to overwriting it doesn't seem to be working for me.

What am I doing wrong?

Is there a better way to accomplish what I'm trying to do?

any help would be GREATLY appreciated!


PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to