I use this to delete line entries from a file, but when I write it back to itself, how do I re organise the data so it doesn't leave blank lines where the data was removed?
<?
$del_data = ""; //variable with new data in it.
$current_line = 0; //to keep track of the line we're on
$write_line = $getline; //line we want to write to
$contents = ""; //variable to store the new file contents in.
$fp = fopen ("target.txt", "r"); //open for reading
while ($data = fgets($fp, 4096)) //This just get's one line of data.
{
$current_line++;
if ($current_line == $write_line)
{
$contents .= $del_data."\n";
} else {
$contents .= $data;
}
}
fclose($fp);
//now write over the file with the new contents
$fp = fopen("target.txt", "w");
fputs($fp, $contents);
fclose($fp);
?>