tomfmason Posted July 20, 2006 Share Posted July 20, 2006 I am wanting to write, between two points, to a html file.say I want it to start at <!--start--> and end at <!--end--> This is what I have now.[code=php:0]$file = "$nick.html";$fp = fopen($file, 'r+'); $newline = "<b>$nick:</b> $message <br>"; while (!feof($fp)){ $line = trim(fgets($fp, 322)); if ($line == '<!--Start of chat-->'){ $fpos = ftell($fp); $rest = fread($fp, filesize($file)); fseek($fp, $fpos, SEEK_SET); fwrite($fp, "\n\n"); fwrite($fp, $rest); fwrite($fp, $newline) } } fclose($fp);[/code]I am wanting to write at the end of the file [code=php:0]<a name="end"></a>[/code]. This way I can jump to the last line in the file.Any suggestions would be great. Quote Link to comment Share on other sites More sharing options...
redarrow Posted July 20, 2006 Share Posted July 20, 2006 what line is that going on Quote Link to comment Share on other sites More sharing options...
tomfmason Posted July 20, 2006 Author Share Posted July 20, 2006 then line number would change each time a message is posted. here is the script that writes the $nick.html[code=php:0]$filename = "$nick.html";$handle = fopen($filename, "x+b");$body = "<p> Welcome <b>$nick</b>, an operator will be with you shortly.</p><!--Start of chat--><!--End of chat--></p>";fwrite($handle, $body);fclose($handle);include('chat.php')[/code]I have tried writeing the new message like this[code=php:0]$file = "$nick.html";$fp = fopen($file, 'r+'); $newline = "<b>$nick:</b> $message <br>"; while (!feof($fp)){ $line = trim(fgets($fp, 322)); if ($line == '<!--Start of chat-->'){ $fpos = ftell($fp); $rest = fread($fp, filesize($file)); fseek($fp, $fpos, SEEK_SET); fwrite($fp, "\n\n"); fwrite($fp, $newline) fwrite($fp, $rest); } }[/code]This posts the new line like this line4 line3 line2 line1. I want it to start with the oldest line then move on to the new lines. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.