Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

fwrite at specific point in file

11:35 am on Sep 10, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:June 7, 2007
votes: 0

Hey there. Here's the first of my problems this week!

I'm doing a little feedback type feature on one of my sites, so a visitor can just type in their name and comment and it's posted to a page (feedback.html) which is displayed in an iframe.

This all works fine and dandy but when I write to the feedback.html page the new comments obviously go on the bottom, so that after a few feedback comments have come in you need to scroll down to read the new ones, so I would like it so that it posts the new comments at the start of the new file. This can't be literally the start though, as the feedback.html has three lines of headers, or 84 characters.

So what I need is a way to point the file pointer at the 85th character or the fourth line and perform the fwrite there. I've tried using fseek but haven't had any joy with that. Does anybody know what I'm talking about and is anyone able to help?


12:13 pm on Sept 10, 2007 (gmt 0)

Preferred Member

10+ Year Member

joined:Jan 16, 2007
votes: 0

this would be way easier if you had a database to contain the comments!
but if you were to continue down your system here are some ways that might help you.

1) Since comments are currently written to the bottom(end) of your feedback.html, what you can do is not necesarily find a way to write to the top, but keep writing to the bottom and display the end of the file first... store each line (using fgets and feof) in an array and backtrack echo.

2) i guess another complicated and long way is to again read the entire file in an array(line by line) when someone posts a comment. add the new comments in after the 3rd line (at array element 3) and rewrite the whole file.

12:39 pm on Sept 10, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:June 7, 2007
votes: 0

So there's no easy way of doing it huh? I was just hoping there was a line of code I could bung in there that would sort it out. Using the database is always an option though.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members