Brian Tully wrote: > 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.
Convert to database. Your hair and your aspirin intake will thank you. > Even though the r+ > option is supposed to put the pointer at the beginning of the file This is correct and is working. > and add > to it as opposed to overwriting This is simply not correct! r+ does not do any magic. It puts the file pointer at the beginning of the file, but it does *NOT* "insert" into the file. files just don't work like that. r+ is *DESIGNED* to let you over-write a file, not put stuff into the top of it. That's why databases were invented. :-) > Is there a better way to accomplish what I'm trying to do? Use a database. If you really, really, really, absolutely insist on sticking to a file-based system, you *COULD* append the new stuff at the end, and then use fopen/fseek to *FIND* the newer stuff. Or if the files are small enough use http://php.net/file to suck the whole thing into an array and interate through it backwards. But if the files are "big" as you claim, then neither of these options is really going to be all that fast. Convert to a database. One *other* option is to store each article in a different file with the date as the name of the file, and then you can snag the new articles fairly quickly by using the file name as the key... Even that won't be as fast and easy as a database. Use a database. Have I said "Use a database" enough times yet? -- Like music? http://l-i-e.com/artists.htm -- 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]