Skip to content

Instantly share code, notes, and snippets.

@BulatSa
Created September 21, 2018 14:25
Show Gist options
  • Save BulatSa/2aed3a4176d12dc57c460c0e246d7e7a to your computer and use it in GitHub Desktop.
Save BulatSa/2aed3a4176d12dc57c460c0e246d7e7a to your computer and use it in GitHub Desktop.
<?php
$file_big = "file-big.txt";
$file_small = "file-small.txt";
$file_clear = "file-clear.txt";
function getLines($file) {
$f = fopen($file, 'r');
try {
while ($line = fgets($f)) {
yield $line;
}
} finally {
fclose($f);
}
}
$arrBig = [];
$arrSmall = [];
foreach (getLines($file_big) as $line) {
$clear_line = str_replace(array("\r","\n"), '', $line);
array_push($arrBig, $clear_line);
}
foreach (getLines($file_small) as $line) {
$clear_line = str_replace(array("\r","\n"), '', $line);
array_push($arrSmall, $clear_line);
}
$result = array_diff($arrBig, $arrSmall);
foreach ($result as $item) :
$content_to_write .= $item . PHP_EOL;
endforeach;
file_put_contents ($file_clear, $content_to_write, FILE_APPEND);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment