Remove duplicate data in a text file with php
php
Solution
This should do the trick:
$lines = file('file.txt');
$lines = array_unique($lines);
`file()` reads the file and puts every line in an array.
`array_unique()` removes duplicate elements from the array.
Also, to put everything back into the file:
file_put_contents('file.txt', implode($lines));
Problem
I am in need to open a text file (file.txt) which contains data in the following format ``` ai bt bt gh ai gh lo ki ki lo ``` ultimately I want to remove all the duplicate lines so only one of each data remains. So the result would look like this ``` ai bt gh lo ki ``` any help with this would be awesome