devWhiz Posted April 29, 2011 Share Posted April 29, 2011 is this possible? Link to comment https://forums.phpfreaks.com/topic/235066-script-to-count-and-remove-duplicate-lines-in-file/ Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 You can use file to read each line into an array. Then use array_unique to grab all unique values. Lastly implode the array back into a string to be written back to the file. Link to comment https://forums.phpfreaks.com/topic/235066-script-to-count-and-remove-duplicate-lines-in-file/#findComment-1208063 Share on other sites More sharing options...
devWhiz Posted April 29, 2011 Author Share Posted April 29, 2011 $filename = 'user_ids.txt'; $text = array_unique(file($filename)); $userids = @fopen($filename,'w+'); if($userids) { fputs($userids, join('',$text)); fclose($userids); } would what you said be more efficient than this? Link to comment https://forums.phpfreaks.com/topic/235066-script-to-count-and-remove-duplicate-lines-in-file/#findComment-1208064 Share on other sites More sharing options...
wildteen88 Posted April 29, 2011 Share Posted April 29, 2011 Yea, that should do fine. Its pretty much what I'd do. join is the same as implode. Link to comment https://forums.phpfreaks.com/topic/235066-script-to-count-and-remove-duplicate-lines-in-file/#findComment-1208068 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.