random access
| From: | Ahmad Khashan | Date: | Sun, 21 Dec 2003 16:15:46 +0000 |
| Subject: | random access | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-22411@lists.php.net to get a copy of this message | ||
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