Sorry, here's an example, say you have a file called "test.txt" with these lines:
First line
Second Line
Third Line
And you want to replace the second line with "New Second Line".
<?
$new_data = "New Second Line"; //variable with new data in it.
$current_line = 0; //to keep track of the line we're on
$write_line = 2; //line we want to write to
$contents = ""; //variable to store the new file contents in.
$fp = fopen ("test.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 .= $new_data."\n"; //put in the new data for this line (change the "\n" to "\r\n" if you're on a windows machine)
} else {
$contents .= $data; //keep the old data for this line
}
}
fclose($fp);
//now write over the file with the new contents
$fp = fopen("test.txt", "w");
fputs($fp, $contents);
fclose($fp);
?>
And then the new "test.txt" will be:
First line
New Second Line
Third Line
Hope that helps. This is what I tried explaining in the first message.