homepage Welcome to WebmasterWorld Guest from 54.196.168.78
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Sorting an email list with PHP?
internetheaven




msg:4585739
 1:59 pm on Jun 19, 2013 (gmt 0)

I have a ex-client email list of 10000+ email addresses. It looks something like this:

email1@company1.com
email2@company1.com
email3@company1.com
email1@company2.org
email2@company2.org
email1@company3.com
email2@company3.com
email3@company3.com
email4@company3.com

is there any way in PHP, Excel or anything - that will organise this list into separate files where only one occurrence of each company name is in each list? e.g.

LIST 1

email1@company1.com
email1@company2.org
email1@company3.com

LIST 2

email2@company1.com
email2@company2.org
email2@company3.com

LIST 3

email3@company1.com
email3@company3.com

LIST 4

email4@company3.com

I've been trying to do it manually, and my eyes are going fuzzy! It's taking forever.

Thanks
Mike

 

jatar_k




msg:4585746
 2:44 pm on Jun 19, 2013 (gmt 0)

I might explode them into a db with fullemail, person, domain and then you could do selects with group by or distinct

you could then store other info and have a little crm going

dmorison




msg:4585819
 5:57 pm on Jun 19, 2013 (gmt 0)

Hi Mike,

With the list saved as list.txt in the same folder, have a go with the following:


<?php
header("Content-Type: text/plain");
$lists = array();
$list = fopen("list.txt","r");
while(!feof($list))
{
$email = trim(fgets($list));
if ($email)
{
$parts = explode("@",$email);
// find the first list without an address for example.com ($parts[1])
$i = 1;
while(isset($lists[$i][$parts[1]])) $i++;
// ...and add the address
$lists[$i][$parts[1]] = $email;
}
}
//dump the lists
foreach($lists as $n => $emails)
{
print "List ".$n."\n\n";
print implode("\n",$emails)."\n\n";
}
?>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved