Getting all lines from a file, and put unique lines in a new file

djlee

New Member
Using PHP I have tried all day to get this done. I failed. I want to:[*]open a directory and read all files there.[*]read each files contents line by line (each line is a name with no spaces (single column)).[*]put each line into a new file (newline by newline).[*]remove duplicate lines.[*]save the new file.Easy for the gurus, mind numbing for me.NOTE: Each file may be 500 lines long and 20 characters per line but, there is only around 20 files.Thanks in advance for the help.Thanks again.Based on the posts below I tried \[code\] $topdir = '/home/mycal25/public_html/processed/';$files = glob($topdir."*.txt"); //matches all text files$lines = array();foreach($files as $file){ $lines = array_merge($lines, file($file, FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES));}$lines = array_unique($lines);file_put_contents($topdir."all/all.txt", implode("\n", $lines));\[/code\]But that did not work...I tried a couple other variations to no avail..
 
Back
Top