...

View Full Version : Processing email address



Developr
07-10-2012, 07:41 AM
I have a mailing list of emails that I had saved but I forgot to use a delimiter when storing them, so my email file looks like this now:

one@one.comtwo@two.netthree@three.co.uk (etc)

How can I automatically add the comma where they should be?

Thanks

jmj001
07-10-2012, 08:25 AM
I would venture to say that you will need to process a large part of it manually

however you could explode the string at different parts to break it down.

For example


$emaildata = 'one@one.comtwo@two.netthree@three.co.uk';
$emailparts = explode("co.uk",$emaildata);

this will give you an array with each element ending co.uk

you'll need to append the co.uk back because the explode function will remove it

then you could run each element again for different domain extensions .com / .net etc...

it will need manual attention too but it should give you a large slice of the addresses

tangoforce
07-10-2012, 08:42 AM
I'd run str_replace() over the whole thing replacing things like:

.com -> .com,
.co..uk -> .co.uk,
.net -> .net,

I think you get the picture..

Developr
07-10-2012, 08:37 PM
I'd run str_replace() over the whole thing replacing things like:

.com -> .com,
.co..uk -> .co.uk,
.net -> .net,

I think you get the picture..

Seems like the best way, thanks!

Developr
07-15-2012, 10:14 PM
Alright so I decided to store them in a database instead but there's a few thousand emails I gotta move to that database and that would obviously be a mammoth task if done manually. I'm trying to create a script that parses them and stores them in my database but I can't get it to work.

I'm using a form so lets say $_POST['emails'] holds the comma separated emails (ex: a@a.com,b@b.com, etc.). While exploding them, I'm trying to store them in a query individually but my method doesn't seem to work. Here's what I have:


$emails = $_POST['emails'];
while($emails = explode($emails,',')) {
$query = mysql_query("INSERT INTO `emails` (`email`) VALUES ('{$emails}') ");
}

Any idea? And yes I'm aware it's unsafe code.

DavidB3ck
07-16-2012, 09:56 PM
Alright so I decided to store them in a database instead but there's a few thousand emails I gotta move to that database and that would obviously be a mammoth task if done manually. I'm trying to create a script that parses them and stores them in my database but I can't get it to work.

I'm using a form so lets say $_POST['emails'] holds the comma separated emails (ex: a@a.com,b@b.com, etc.). While exploding them, I'm trying to store them in a query individually but my method doesn't seem to work. Here's what I have:


$emails = $_POST['emails'];
while($emails = explode($emails, ',')) {
$query = mysql_query("INSERT INTO `emails` (`email`) VALUES ('{$emails}') ");
}

Any idea? And yes I'm aware it's unsafe code.

Why are you using a form instead of parsing the file directly? Depending on how much data you have, the form may not be able to hold it all.

However, either way, you may want to condense this all into a single query.



$emails = explode(',', $_POST['emails']);
$emails = '\'' . implode('\', \'', $emails) . '\'';

mysql_query('INSERT INTO `emails` (`email`)
VALUES (' . $emails . ')');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum