Does anyone know either in PHP or Perl or CGI (so I can run it via cronjob) how to take the contents of say file1.txt and paste it to the end of file3.txt and then do the same with file2.txt to the end of file3.txt
This works for DOS:
append.bat
Contents of file1.txt:
Contents of file2.txt:
Expected Result/Expected Contents of file3.txt:
Note: Does not 'overwrite' any part, and must end the line ("\n" in php) at the end of pasting each file. To prevent output like this:
This is what I have written in a .php file:
[php]<?PHP
$fp2 = fopen('file2.txt', 'r');
$fp = "file3.txt";
if (!($fp = fopen('file3.txt', 'a'))) {
die('Cannot open log file');
}
if (!($fp1 = fopen('file1.txt', 'r'))) {
die('Cannot open log file');
}
if (!($fp2 = fopen('file2.txt', 'r'))) {
die('Cannot open log file');
}
fwrite($fp, file1.txt);
fwrite($fp, $f2);
fclose($fp);
fclose($fp1);
fclose($fp2);
?>[/php]However, this only writes:
It doesn't write the contents of file1.txt - and seems to ignore the file2 part, I have tweaked it a lot, testing different ways.
I think for PHP, I'll have to store the contents of file1.txt into an array, then set that array as string data then write the string data into file3.txt then do the same for file2.txt - but I don't know how to do that, and there may be a simpler way.
This works for DOS:
append.bat
Code:
@echo off for /f "tokens=* delims=" %%J in (file1.txt) do echo %%J >> file3.txt for /f "tokens=* delims=" %%J in (file2.txt) do echo %%J >> file3.txt
Code:
hello world
Code:
world - how are you? I am good.
Code:
hello world world - how are you? I am good.
Code:
hello worldworld - how are you? I am good.
[php]<?PHP
$fp2 = fopen('file2.txt', 'r');
$fp = "file3.txt";
if (!($fp = fopen('file3.txt', 'a'))) {
die('Cannot open log file');
}
if (!($fp1 = fopen('file1.txt', 'r'))) {
die('Cannot open log file');
}
if (!($fp2 = fopen('file2.txt', 'r'))) {
die('Cannot open log file');
}
fwrite($fp, file1.txt);
fwrite($fp, $f2);
fclose($fp);
fclose($fp1);
fclose($fp2);
?>[/php]However, this only writes:
Code:
file1.txt
I think for PHP, I'll have to store the contents of file1.txt into an array, then set that array as string data then write the string data into file3.txt then do the same for file2.txt - but I don't know how to do that, and there may be a simpler way.

Comment