I want to write on line 5 of my file.
I can't use replace because my file use many numbers in lines. So I need to know how can modify line 5.
You know we can read line 5 of file with:
$File='myfile.txt';
$readline = file($File);
$line5=$readline[4];'
I need to code that can modify only line 5 of $File
.
In your code $read
is undefined. It should be $readline
, the following should work for you:
$File = 'myfile.txt';
$lines = file($File);
$lines[4] = 'modified line';
file_put_contents($File, implode("
", $lines));