3
我試圖做一個簡單的PHP來讀取和刪除文本文件的第一行。如何從文本文件中刪除第一行php
到目前爲止,我得到了代碼:
<?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的前兩行唯一的工作,但是當它應該閱讀第三行的代碼停止工作。任何建議請。
所需要的正是我。謝謝。 – Robert
@Robert ok然後你可以批准答案,如果它已經解決了你的問題 – Ghostman
所以即使你知道這是一個重複的問題! – RiggsFolly