Re: Sort User List

From: Date: Tue, 04 Jul 2000 02:24:19 +0000
Subject: Re: Sort User List
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-4651@lists.php.net to get a copy of this message
In article <20000701233854.42789.qmail@hotmail.com>, nicholascatalano@hotmail.com ("Nick Catalano") wrote: > ok... Our server just got hacked, and I have to add all these users in by > hand, into the controll pannel of our Raq3... to make this job easier I want > to write a script on my machine to sort all the users and there email > addresses into easy to use files. Only problem: I have no clue how to use > the fopen and explode commands!!! > > =++ The Situation ++= > I have a list of users that is setup something like this, line after line: > emailaddy@domain username > dada@www.dadauniverse.com dadauser > meme@www.memecenter.com meami > > how could I do a explode and use a array to sort ALL of them (there are a > TON) into different files according to there domain?? The file with all the > users is enormous, and is in no order at all... I know I would have to do a > fopen() then a explode("\n") or something like that, but I am not sure, > anyone have a clue?? How enormous is enormous... It will be RAM-intensive, but this should work... If it chokes on RAM, you'll have to do partial sorts and whatnot. Some Perl hacker or real Un*x geek will be able to give you a way to do it with just "sort" in a shell... <?php //Suck entire file into array: $file = file('/path/to/userlist') or die("Could not open userlist"); function domaincmp($user1, $user2){ $data1 = explode('@', $user1); $data2 = explode('@', $user2); $domain1 = $date1[1]; $domain2 = $date2[1]; return strcmpi($domain1, $domain2); } usort($file, 'domaincmp'); $lastdomain = ''; $output = 0; reset($file); while(list(,$user) = each($file){ $data = explode('@', $user); $domainemail = $data[1]; $data = explode(' ', $domainemail); $domain = $data[0]; if ($domain != $lastdomain){ if ($output){ fclose($output); } $path = "/some/writable/directory/$domain"; $output = fopen($path, 'w') or die("Could not open $path"); } fputs($output, $user); } if ($output){ fclose($output); } ?> -- Richard Lynch | If this was worth $$$ to you, buy a CD US Customer Support Director | from one of the artists listed here: Zend Technologies USA | http://www.L-I-E.com/artists.htm http://www.zend.com | (this has nothing to do with Zend, duh!)

« previous php.general (#4651) next »