加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

如何使用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); 

?>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读