Skip to content

Instantly share code, notes, and snippets.

@FrancoStino
Last active February 26, 2021 08:52
Show Gist options
  • Save FrancoStino/ff11854f0f5e8cde4a3c7b2f87a8ead8 to your computer and use it in GitHub Desktop.
Save FrancoStino/ff11854f0f5e8cde4a3c7b2f87a8ead8 to your computer and use it in GitHub Desktop.
Merge 2 file TXT into one with separator.php
<?
$files1 = file('Anagrafica_Articoli.txt'); // read file1.txt
$files2 = file('Livello1.txt', FILE_IGNORE_NEW_LINES); // read file2.txt
// Assuming both files have equal amount of rows.
for($x = 0; $x < count($files1); $x++) {
$files1[$x] = str_replace(array("\n", "\r"), "", $files1[$x]);
$files3[$x] = $files1[$x]."".$files2[$x];
}
$result = implode("|\n", $files3);
// combines the array to a single string.
if(file_put_contents('prova.txt', $result)) { // puts the imploded string into file3.txt
echo "Writing to file 'prova.txt' was successfull.";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment