龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php 逐行删除文件中的内容

时间:2014-07-12 15:11来源:网络整理 作者:网络 点击:
分享到:
逐行删除文件中的内容 [代码片段(18行)]
function delline($file)
{
    $fp = fopen($file,"r");
    $tmp = tempnam("./","temp0");
    $tmp_fp = fopen($tmp,"w");
    $i=0;
    while(!feof($fp)){
        $line = fgets($fp);
        if($i!=0){
            fputs($tmp_fp,$line);
        }
        $i++;
    }
    fclose($fp);
    fclose($tmp_fp);
    rename($tmp,$file);
}
//该片段来自于http://outofmemory.cn
精彩图集

赞助商链接