Created
September 21, 2018 14:25
-
-
Save BulatSa/2aed3a4176d12dc57c460c0e246d7e7a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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