Jump to content


Photo

write between two points in a html file.


  • Please log in to reply
2 replies to this topic

#1 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 20 July 2006 - 03:17 AM

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.

$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);

I am wanting to write at the end of the file
<a name="end"></a>
. This way I can jump to the last line in the file.

Any suggestions would be great.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 July 2006 - 03:20 AM

what line is that going on
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 20 July 2006 - 03:35 AM

then line number would change each time a message is posted.

here is the script that writes the $nick.html

$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')

I have tried writeing the new message like this

$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);
  		 
	}		 
}

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.

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users