Can you delete/overwrite a specific line on a text document with PHP? I know you can overwrite a whole document, but I just want to take out or overwrite a specific line. Is that possible? It would make my data folder a lot less convoluted.
Thanx for any help.
[code=php]<?php // replace line 5 $textfile = 'textfile.text'; //Read file $lines = @file($textfile) or die('I could not open '.$textfile); $newtext = 'This is the new line 5'."n"; $lines[4] = $newtext; // keys start at 0... key 4 = line 5 // write file $f = fopen($textfile, 'w') or die('I could not open '.$textfile); fwrite($f, implode('', $lines)); fclose($f); ?>[/code]
Help @urquanmaster spread the word by sharing this article on Twitter...