I am in need to open a text file (file.txt) which contains data in the following format :-
dave : 50lb : hlof
jimmy : 55lb : okay
dave : 12lb : krsho
I want to remove lines that has duplicate start word So the result would look like this :-
dave : 50lb : hlof
jimmy : 55lb : okay
I've been thinking about using array_unique
but didn't worked so any idea how it can be done .. maybe can be with regex
!
Update
my try was
$lines = file('file.txt');
$lines = array_unique($lines);
file_put_contents('file.txt', implode($lines));
but didn't worked cause it only compare the whole line if not the same will then consider it different
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…