如何使用php删除文件的最后一行?
发布时间:2020-12-13 13:21:13 所属栏目:PHP教程 来源:网络整理
导读:我尝试了很多潜在的解决方案,但没有一个能为我工作. 最简单的一个: $file = file('list.html');array_pop($file); 什么都没做.我在这里做错了吗?它是不同的,因为它是一个HTML文件? 这应该有效: ?php // load the data and delete the line from the arra
我尝试了很多潜在的解决方案,但没有一个能为我工作.
最简单的一个: $file = file('list.html'); array_pop($file); 什么都没做.我在这里做错了吗?它是不同的,因为它是一个HTML文件?
这应该有效:
<?php // load the data and delete the line from the array $lines = file('filename.txt'); $last = sizeof($lines) - 1 ; unset($lines[$last]); // write the new data to the file $fp = fopen('filename.txt','w'); fwrite($fp,implode('',$lines)); fclose($fp); ?> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |