random access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Assuming a record length of 100 characters and i want to read approximately the last 5 records, here is the code:
------code-----
<html>
<body>
<?php
$nchars = -500;
$handle = fopen ("access.log", "r");
if(!$handle){
 echo(" problem opening the users file for read...");
 exit();
}
echo("<h4>Last n records read in last 500 characters:</h4>");
echo("<hr>");
fseek($handle , $nchars, SEEK_END);              // 
$buf = fgets($handle, 100);    // will read till a newline inclusive. 
// ignore this record. I might be in the middle of it.
$icount = 0;
while (!feof ($handle)) {
  $buf = fgets($handle, 100);
    echo ("$buf <br />");   
    $icount ++;
  }
fclose ($handle);
echo(" <h4>Number of records in last 500 characters is: $icount</h4>");
?>
</body>
</html>
----end code----
good luck. Ahmad
 


---------------------------------
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux