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?
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.