homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

fwrite at specific point in file
Robert Poole

5+ Year Member

Msg#: 3446217 posted 11:35 am on Sep 10, 2007 (gmt 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?




5+ Year Member

Msg#: 3446217 posted 12:13 pm on Sep 10, 2007 (gmt 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.

Robert Poole

5+ Year Member

Msg#: 3446217 posted 12:39 pm on Sep 10, 2007 (gmt 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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved