hey, I have had this question myself. I needed to make a log of IP addresses that went on my site. The thing is that I wanted to make each new IP add a row of an existing table written in HTML. I had to 'chop' the variable(which included the entire HTML code) into a couple of parts(header, body and footer). The code breaks up the variable into sections and puts each section into an array. In my HTML file, I added an HTML comment "<!--break-->" which does nothing in the web browser when ran, but this is where the pieces get chopped up by the PHP code into sections. Then later I include the "<--break-->" comment again for further processing. This script works really good, It got me very excited when I actually did this the first time . Here is my PHP code:(look for the '$pieces = explode("<!--break-->", $ffh);' part, this is the code you need)
<?php
//Create TXT of log
//Get Remote IP into $IP variable
$IP=$_SERVER['REMOTE_ADDR'];
//Display $IP variable on Client
echo "Your IP is:";echo $IP;
//Set file to be edited into variable $IPFile
$IPFile = "Data/Logs/IPLog.txt";
//Open File to be edited, "Append" Mode into $fh variable
$fh = fopen($IPFile, 'a') or die("can't open file");
//Write IP into file specified in $fh variable each line
fwrite($fh, $IP);
fwrite($fh, " Accessed:");
fwrite($fh, date("d/m/y H:i:s",time()));
fwrite($fh, "
");
//Close $fh variable(close file)
fclose($fh);
?><?php
//Create HTML of LOG !!!No Auto Refresh inside log!!!
//Declare File to be written into variable
$IPFileHTML = "Data/Logs/IPLog.html";
//if Declare file does NOT exsist, show error message and create new file
if (!file_exists($IPFileHTML)) {
echo "<br>IPTRACELOG not found, New Log being created.";
fopen($IPFileHTML, 'w') or die("cannot create log file, check permissions. If you do not have permissions, contact your system administrator");}
//Get contents of that file
$ffh = file_get_contents("Data/Logs/IPLog.html");
//break contents into an array, <!--break--> identifies where to split file
$pieces = explode("<!--break-->", $ffh);
//open declared variable to be written to
$fh = fopen($IPFileHTML, 'w') or die("can't open file to write");
//write new file replacing old one every time this page is loaded
fputs($fh, "<html><title>IP TRACE LOG</title><script language='javascript' type='text/javascript'>function refresh(){window.location.href='IPLog.html';setTimeout('setTimeout()', 2000); }</script><body bgcolor='#C0C0C0'><center><h1>USAGE LOG</h1><table bgcolor='#FF8C00' border=5><tr><th>IP</th><th>Acessed Date/Time</th></tr><!--break-->");
fputs($fh, "<tr><td>");
fputs($fh, $_SERVER['REMOTE_ADDR']);
fputs($fh, "</td><td>");
fputs($fh, date("d/m/y H:i:s",time()));
fputs($fh, "</td></tr>");
fputs($fh, $pieces[1]);
fputs($fh, "<!--break--></table></center></body></html>");
fclose($fh);
?>
Hope this helps:) God Bless:)