我将尝试制作一个简单的PHP程序,用于读取并删除文本文件的第一行。
目前我已经有了以下代码:
代码仅适用于text.txt中的前两行,但当它应读取第三行时,代码停止工作。请问有何建议?
目前我已经有了以下代码:
<?php
$myfile = fopen("text.txt", "r") or die("Unable to open file!");
$ch=1;
while(!feof($myfile)) {
$dataline= fgets($myfile);
$listes = explode("\n",file_get_contents("text.txt"));
$poc = $listes[0];
if($ch == 2){
$gol = str_replace(' ', ' ', $dataline)."\n";
$fh = fopen("newtext.txt",'a');
fputs($fh, $gol);
fclose($fh);
chmod("newtext.txt", 0777);
}
$ch = 2;
}
unlink("text.txt");
copy("newtext.txt", "text.txt");
chmod("text.txt", 0777);
unlink("newtext.txt");
fclose($myfile);
echo $poc;
flush();
?>
代码仅适用于text.txt中的前两行,但当它应读取第三行时,代码停止工作。请问有何建议?