---
title: "Log file viewer in PHP"
description: "= 0) { $position = $position - $chunklen; if ($position = $numtoget + 1) { pregmatch(’!(.?n){’.($numtoget-1).’}$!’, $data."
url: "https://h3manth.com/scribe/log-file-viewer-php/"
canonical_url: "https://h3manth.com/scribe/log-file-viewer-php/"
markdown_url: "https://h3manth.com/scribe/blog/log-file-viewer-php.md"
publishDate: "2010-02-09T00:00:00.000Z"
author: "Hemanth HM"
category: "linux"
tags: ["linux","opensource"]
word_count: 77
reading_time_minutes: 1
x_markdown_tokens: 255
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Log file viewer in PHP

> = 0) { $position = $position - $chunklen; if ($position = $numtoget + 1) { pregmatch(’!(.?n){’.($numtoget-1).’}$!’, $data.

= 0)
  {
    $position = $position - $chunklen;
    if ($position < 0) { $chunklen = abs($position); $position=0;}
    fseek($fp, $position);
    $data = fread($fp, $chunklen). $data;
    if (substr_count($data, "\n") >= $num_to_get + 1)
    {
       preg_match("!(.*?\n){".($num_to_get-1)."}$!", $data, $match);
       return $match[0];
    }
  }
  fclose($fp);
  return $data;
} 

function show_log($log){
	$data=tail('$log');
	$data = explode("\n",$data);
	while (list($var, $val) = each($data)) {
    ++$var;
    $val = trim($val);
    print "$val 
";
}
	print "";
}

**Click on the links to see the logs**

[Apache-Access-Log]()

[Apache-Error-Log]()

[Clear]()
