t_k_eoh Posted August 1, 2007 Share Posted August 1, 2007 Hi guys, Appreciate if you can lend me a hand on the following: I have a file (output.txt) which has lots of words in it (words are saved in "\n"), I would like to sort the words and then save it into another file (data.txt). How do I do it? I know how to open the output.txt file and read it but i don't know how to call it out into an array, remove duplicated words and sort it. Can you pls help?? Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/62781-load-txt-remove-duplication-and-save-into-txt/ Share on other sites More sharing options...
trq Posted August 1, 2007 Share Posted August 1, 2007 <?php $lines = file('output.txt'); $lines = array_unique(sort($lines)); $f = fopen('data.txt','w'); foreach($lines as $line) { fwrite($f,$line."\n"); } fclose($f); ?> Quote Link to comment https://forums.phpfreaks.com/topic/62781-load-txt-remove-duplication-and-save-into-txt/#findComment-312564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.