建站学习(PHP+apache+mysql):2 将日志在页面展示

来源:互联网 发布:java中parse什么意思 编辑:程序博客网 时间:2024/05/20 16:41

一、读取文件并展示
<!DOCTYPE html>
<html>
<body>

<?php
$file = fopen("../Apache-20/logs/access.log","r");//打开文件;注意文件访问方式:php执行在htdocs目录下,跨目录的/apache-20/log对其可读
while(! feof($file))
  {
  echo fgets($file). "<br />"; //将日志取出一行并展示
  }

fclose($file); //关闭文件
?>

</body>
</html>

二、读取文件并写入文件

<!DOCTYPE html>
<html>
<body>

<?php
//echo readfile("webdictionary.txt");
//$file = fopen("webdictionary.txt","r");
$file = fopen("../Apache-20/logs/access.log","r");
$myfile = fopen("../Apache-20/logs/mr_log", "w") or die("Unable to open file!");
while(! feof($file))
  {
      $tmp=fgets($file). "<br />";
    fwrite($myfile, $tmp);  // 注意文件访问方式:php执行在htdocs目录下,跨目录的/apache-20/log对其可写入
  }

fclose($file);
fclose($myfile);
?>

</body>
</html>


0 0