Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Processing email address

    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

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    271
    Thanks
    2
    Thanked 65 Times in 65 Posts
    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

    PHP Code:
    $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
    hey... it's a sig..

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,313
    Thanks
    58
    Thanked 525 Times in 512 Posts
    Blog Entries
    5
    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..
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • #4
    New Coder
    Join Date
    Mar 2009
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    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!

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
                    $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.

  • #6
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by Developr View Post
    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:

    PHP Code:
                    $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.

    PHP Code:
    $emails explode(','$_POST['emails']);
    $emails '\'' implode('\', \''$emails) . '\'';

    mysql_query('INSERT INTO `emails` (`email`)
    VALUES (' 
    $emails ')'); 
    Last edited by DavidB3ck; 07-16-2012 at 10:04 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •