Jump to content

write between two points in a html file.


tomfmason

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.