Forum Moderators: coopster
<?php
$body = '<div>'.date('H:i:s').'</div>'."\n";
$file = 'log11.html';
$result1 = fopen($file,'a+');
if ($result1)
{
$result2 = fread($result1,filesize($file));
if ($result2)
{
$append = $body.$result2;
fclose($result1);
$result3 = $result1 = fopen($file,'w');
if ($result3)
{
$result4 = fwrite($result3,$append);
if ($result4)
{
fclose($result1);
$result5 = fopen($file,'r+');
if ($result5)
{
$result6 = fread($result5,filesize($file));
if ($result6)
{
echo $result6;
}
else {echo 'error 5';}
}
else {echo 'error 5';}
}
else {echo 'error 4';}
}
else {echo 'error 3';}
}
else {echo 'error 2';}
}
else {echo 'error 1';}
?>
<?php
$data = '<div>'.date('H:i:s').'</div>'."\n";
$data .= file_get_contents('log11.html');
file_put_contents('log11.html',$data);
?>
<?php
$file = 'log11.html';
$result1 = fopen($file,'c');
if ($result1)
{
$body = '<div>'.date('H:i:s').'</div>';
$result2 = fwrite($result1,$body);
if ($result2)
{
fclose($result1);
$result3 = fopen($file,'r');
if ($result3)
{
$result4 = fread($result3,filesize($file));
if ($result4)
{
echo $result4;
}
else {echo 'error 4';}
}
else {echo 'error 3';}
}
else {echo 'error 2';}
}
else {echo 'error 1';}
?>
$body = '<div>'.date('H:i:s').'</div>'."\n";
$file = 'log11.html';
$result1 = fopen($file,'a+');
if ($result1)
{
$result2 = fread($result1,filesize($file));
if ($result2)
{
$append = $body.$result2;
fclose($result1);
$result3 = $result1 = fopen($file,'w');
if ($result3)
{
$result4 = fwrite($result3,$append);
if ($result4)
{
fclose($result1);
$result5 = fopen($file,'r+');
if ($result5)
{
$result6 = fread($result5,filesize($file));
if ($result6)
{
echo $result6;
}
else {echo 'error 5';}
}
else {echo 'error 5';}
}
else {echo 'error 4';}
}
else {echo 'error 3';}
}
else {echo 'error 2';}
}
else {echo 'error 1';}
I took a second shot at trying to get this to work however it overwrites the first line and keeps all the other lines in tact below it. Adding a \n line break on Windows XP to the end of the $body variable interfered with the second line and broke the XHTML which was odd.
then I imagine that those working with lines in flat files probably make use of exploding line breaks.