Forum Moderators: coopster
can anyone please tell me how i can open a data.txt file and remove the first line and then save it.
thanx
fopen
file [ca3.php.net]
remove the first element from the resulting array
fwrite (using a loop or implode first then write)
fclose
$arrayOfLines=file [php.net]('yourfilename');
$linesIWant=array_slice [php.net]($arrayOfLines,3);
$fileContents=implode("\n",$linesIWant);
$fp=fopen('newfile','w+');
fwrite($fp,$fileContents);
fclose($fp);
function delxlines($txtfile, $numlines)
{
if (file_exists("temp.txt"))
{
unlink("temp.txt");
} $arrayz = file("$txtfile");
$tempWrite = fopen("temp.txt", "w");
for ($i = $numlines; $i < count($arrayz); $i++)
{
fputs($tempWrite, "$arrayz[$i]");
}
fclose($tempWrite);
copy("temp.txt", "$txtfile");
unlink("temp.txt");
}