2-08 2,100 views
<?php
function getLines($file) {
$f = fopen($file, 'r');
try {
while ($line = fgets($f)) {
yield $line;
}
} finally {
fclose($f);
}
}
foreach (getLines("logs.log") as $n => $line) {
//逐行内容
echo $line;
//行数
var_dump($n);
}