Small file, just put it in an array as suggested.
Large file?
Then read here how you can open a large file:
Reading very large files in PHP
Did 2 tests with a 1.3GB file and a 9.5GB File.
1.3 GB
Using fopen()
This process used 15555 ms for its computations.
It spent 169 ms in system calls.
Using file()
This process used 6983 ms for its computations.
It spent 4469 ms in system calls.
9.5 GB
Using fopen()
This process used 113559 ms for its computations.
It spent 2532 ms in system calls.
Using file()
This process used 8221 ms for its computations.
It spent 7998 ms in system calls.
Seems file() is faster.
Now process the file line by line. For every line, just use:
$linearr = explode(",",$line);
Now add $line[0]
to the end of outputfile 1 and $line[1]
to the end of outputfile 2.
Two ways to do the appending are described here:
Create or write/append in text file
$txt = "user id date";
$myfile = file_put_contents('logs.txt',$txt.PHP_EOL , FILE_APPEND | LOCK_EX);
or
$myfile = fopen("logs.txt", "a") or die("Unable to open file!");
$txt = "user id date";
fwrite($myfile, "\n". $txt);
fclose($myfile);