需要函数:
fopen($file, "r")打开文件 fgets($file, 1024 * 10)读取一行,注意设置字节数大小,默认的1024B可能太小了 strpos($log, '---') 找到某一标记首次出现的位置 trim()去除空格 substr($pre, 0, $index_q)截取某一标记之间的字符 explode()通过某标记转为数组 end($logs)将 array的内部指针移动到最后一个单元并返回其值
AI 代码解读
<?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); } }
AI 代码解读