Last active
February 26, 2021 08:52
-
-
Save FrancoStino/ff11854f0f5e8cde4a3c7b2f87a8ead8 to your computer and use it in GitHub Desktop.
Merge 2 file TXT into one with separator.php
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
<? | |
$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