Zubrag.com
October 22, 2019, 10:42:53 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Remove duplicate lines from a file  (Read 16844 times)
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« on: November 02, 2007, 03:41:04 AM »

Remove duplicate lines from a file.

<?php

// filename
$filename = 'cars.txt';

$text = array_unique(file($filename));

$f = @fopen($filename,'w+');
if ($f) {
  fputs($f, join('',$text));
  fclose($f);
}

?>
Change cars.txt above to target file name. Result will be saved into the same file.
If you want to same result to another file replace $f = @fopen($filename,'w+');  with $f = @fopen('result-file-name.txt','w+');

Logged
YellowNick
Newbie
*
Posts: 1


« Reply #1 on: February 02, 2012, 10:15:23 AM »

Yes this is just what I need. I have a huge file with lots of duplicates.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC