graziano68 — 2013-09-24T08:53:06-04:00 — #1
I have a data.txt file containing data like this
house # john
car # smith
boat # john
I need to remove from file data.txt , all rows having "# john" . I can load the file in array because it's a very big file and I receive a memory error.
Is there any way to remove all rows having "# john" in the file , without loading the file in array ?
cpradio — 2013-09-24T09:08:40-04:00 — #2
You will want to use fgets, write lines you want to keep to a new file, something like the below
$oldfile = fopen('mylargefile.txt', 'r');
$newfile = fopen('mynewlargefile.txt', 'w');
while (($currentLine = fgets($oldfile)) !== false)
if (strpos($currentLine, '# john') === false) // line did not contain # john
graziano68 — 2013-09-24T09:22:00-04:00 — #3
excellent way , thank you.