> the problem with reading the file into an array is that the lines are
irregular:
abd245cf | dsgf ; . | d.kjfd | ::kdijh | . | kjdf | | ""
I can't modify what that string looks like, so I'm not sure if I can use
explode.
perhaps I could append the new string on the bottom, then use fseek and
fread to copy what I want into a variable, then just paste it back in - but the
syntax for this is killing me...
developing...
"Garp" <ga***@no7.blueyonder.co.uk> wrote in message
news:hQ*******************@news-text.cableinet.net...
"deko" <dj****@hotmail.com> wrote in message
news:dp*******************@newssvr25.news.prodigy. com... I'm not sure how to do this in php - need to calculate and delete an
unspecified number of lines from the *top* of a file.
<?php
//append $visitor to the bottom of $visdata
$fp = fopen($visdata,"a");
fwrite($fp, "\n".$visitor;)
//count the lines in $visdata
$lines = count($visdata);
if $lines > 10
{
//delete as many lines off the top as necessary
//to end up with 10 lines total in $visdata
}
fclose($fp);
?>
suggestions welcome! Thanks!
$filearray=file($visdata);
$fp = fopen($visdata,"w");
$c=count($filearray);
for($i=($c < 10 ? 0 : $c-10);$i < $c;++$i) {
fputs($fp,$filearray[$i]);
}
fclose($fp);
(Handcrafted and untested at 6am, no warranty implied).
Garp
I'm going to say three more things, then I'm going to start charging, or
posting my own bugs. 8)
1) Stop top-posting, or I'm-a have to kill you.
2) You asked for a way of cutting all but the bottom ten lines. In my world,
a "line" terminates in a linefeed. file() reads a file in, dividing by
linefeeds and returning an array, and with the minimum of fuss.
3) With the amount of work you've put in to this, you could have learned the
MySQL interfaces.
Still, I wish you luck.
Garp