阅读php和txt中的某些行
我应该读一个txt吗,在这里我们开始,现在我如何才能做到只需要最后10行文字? 实例 如果txt I 你好1 你好2 你好3 你好4 你好,5号 我只想打印成视频 你好4 你好,5号, 我该怎么做?? 提前谢谢 这是密码阅读php和txt中的某些行,php,logging,Php,Logging,我应该读一个txt吗,在这里我们开始,现在我如何才能做到只需要最后10行文字? 实例 如果txt I 你好1 你好2 你好3 你好4 你好,5号 我只想打印成视频 你好4 你好,5号, 我该怎么做?? 提前谢谢 这是密码 $conta_td = 1; $numero_td = 1; echo " <table class=\"table table-striped table-bordered table-hover\"> <tbody>"; $f = fopen("
$conta_td = 1;
$numero_td = 1;
echo " <table class=\"table table-striped table-bordered table-hover\"> <tbody>";
$f = fopen("Func/form_ipn.log", "r");
while (!feof($f)) {
$array = explode(",",fgets($f));
$row = current( $array );
if ($conta_td == 1){
echo "<tr>";
echo"<td>$row </td>";
if ($conta_td == $numero_td) {
echo "</tr>";
$conta_td = 1;
} else {
$conta_td++;
}
}
if ($conta_td!= 1) {
while ($conta_td <= $numero_td) {
echo "<td> </td>";
$conta_td++;
}
echo"</tr>";
}
echo " </tbody></table>";
你需要更新你的逻辑 将整个文件加载到数组中 确定数组中的行 为阵列中的最后10个元素运行输出周期 编辑:输出周期示例
function outputLastN($array, $howmany){
if($howmany > 0 && count($array) > 0 && count($array) >= $howmany){
echo "<table>";
for($i=(count($array)-$howmany);$i<count($array);i++){
echo "<tr>";
echo "<td>".$i."</td>";
echo "<td>".$array[$i]."</td>";
echo "</tr>";
}
echo "</table>";
}
}
?>
我还要为你指出一些好的做法
缩进你的代码-它使它更可读,更容易调试
使用函数或可能是面向对象的方法—当您将代码分割成更小的可重用片段,并由它们自己负责特定任务时(例如输出、文件数据加载等),这会使思考代码变得更容易,。。。
始终尝试拆分代码逻辑和视图。它使事情更模块化,更易于维护
我想要只独角兽:你不会把文件丢了吧?另外,学习缩进的重要性。无论fclose函数是在以后的时间,你可以按照我的要求做吗?