How can I remove a line from a file pointer in PHP? I open the file using fgets()
and not with file()
because the file is too big.
The actual problem is: I have 2 very big files. I need to remove all lines from file 1 which exist in file 2.
This is the code:
$handle1 = fopen("1.txt", "r+");
$handle2 = fopen("2.txt", "r");
if ($handle2) {
while (!feof($handle2)) {
$buffer2 = trim(fgets($handle2));
if ($handle1) {
while (!feof($handle1)) {
$buffer1 = trim(fgets($handle1));
if($buffer1 == $buffer2)
// stuck here
}
fclose($handle1);
}
}
fclose($handle2);
}
How the line can be removed?
Thanks!