I have a text file which I am trying to remove duplicate lines.
Text file example:
new featuredProduct('', '21640'),
new featuredProduct('', '24664'),
new featuredProduct('', '22142'),
new featuredProduct('', '22142'),
new featuredProduct('', '22142'),
new featuredProduct('', '22142'),
new featuredProduct('', '22142'),
The PHP Code I've tried:
$lines = file('textfile.txt');
$lines = array_unique($lines);
file_put_contents('textfile.txt', implode($lines));
The PHP file is called duplicates.php and the textfile is in the same directory. I would like to be left with only:
new featuredProduct('', '21640'),
new featuredProduct('', '24664'),
new featuredProduct('', '22142'),
The file function is trying to read the file into the $lines array then array_unique() to remove the duplicate entries. Then put the filtered results back in the same file.