Loading

PHP读取日志里数据方法理解

需要函数:

fopen($file, "r")打开文件
fgets($file, 1024 * 10)读取一行,注意设置字节数大小,默认的1024B可能太小了
strpos($log, '---') 找到某一标记首次出现的位置
trim()去除空格
substr($pre, 0, $index_q)截取某一标记之间的字符
explode()通过某标记转为数组
end($logs)将 array的内部指针移动到最后一个单元并返回其值
<?php
header("Content-type:text/html;charset=utf-8");

$file = 'test.txt';

$fp = @fopen($file,'r');
if($fp){
	while(!feof($fp)){
		$line = fgets($fp, 1024);
		var_dump($line);
	}
}
posted @ 2015-11-19 16:31  飞鸿影  阅读(1216)  评论(0编辑  收藏  举报