一、读取文件并展示
<!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>