Advertisement
d34n

log reader php

Aug 30th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. <?php
  2. $maxlines=5000;
  3. $fp=fopen('log.txt','r');
  4. if(!$fp) exit("couldn't open log");
  5. if(isset($_GET['start'])) $start=$_GET['start']; else {
  6. $cnt=0;
  7. while(!feof($fp)){ $line=fgets($fp); $cnt++; }
  8. rewind($fp);
  9. if($cnt>$maxlines) $start=$cnt-$maxlines-1; else $start=0;
  10. }
  11. $i=0;
  12. while(!feof($fp)){
  13. $line=fgets($fp);
  14. if(empty(trim($line))) continue;
  15. if(strpos($line,'****')!==false) continue;
  16. if($i<$start){ $i++; continue; }
  17. echo $line;
  18. $i++;
  19. }
  20. echo "/*asdf*/$i"; // output separator and current highest line number
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement