SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Looking for code to parse a list of email addresses separated by comma

    Hi,

    I am looking for a nifty code that would parse a list of email addresses separated by comma.

    So for example say there is a list of email addresses like:

    jon@x.com, jane@y.net, jad@z.edu
    etc.

    What I am looking for is a code, a function, that retrieves each email from above text string, so that each email can be individually addressed and saved.

    Thank you for your help in this matter.

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    explode()

  3. #3
    SitePoint Evangelist achintya's Avatar
    Join Date
    Apr 2005
    Location
    Chandannagar(India)
    Posts
    459
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, you have to use explode like this
    PHP Code:
    $array explode(',',$your_comma_seperated_email_list); 
    after that using foreach loop you can fetch each of this email adresses like this
    PHP Code:
    foreach($array as $email_address)
    {
         
    //do your job

    If you need further assistance,please reply.

  4. #4
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your suggestion.
    It seems to be working very nicely.

    Cheers


    Quote Originally Posted by achintya View Post
    Yes, you have to use explode like this
    PHP Code:
    $array explode(',',$your_comma_seperated_email_list); 
    after that using foreach loop you can fetch each of this email adresses like this
    PHP Code:
    foreach($array as $email_address)
    {
         
    //do your job

    If you need further assistance,please reply.

    Anoox search engine volunteer

    www.anoox.com

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,609
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If the comma-separated list really does have a space after each comma, then you might want to trim() each $array element.

    PHP Code:
    foreach($array as $email_address)

    {

         
    $email_address trim ($email_address);
         
    //do your job


    Ian Anderson
    www.siteguru.co.uk

  6. #6
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    BTW, I forgot to thank U for this suggestion.
    ThanX

    Quote Originally Posted by siteguru View Post
    If the comma-separated list really does have a space after each comma, then you might want to trim() each $array element.

    PHP Code:
    foreach($array as $email_address)

    {

         
    $email_address trim ($email_address);
         
    //do your job



    Anoox search engine volunteer

    www.anoox.com

  7. #7
    SitePoint Enthusiast Aken's Avatar
    Join Date
    Oct 2007
    Location
    Racine, Wisconsin, USA
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also include the space inside the explode() function after the comma.
    Eric Roberts - Racine, WI Web Design & Development
    www.cryode.com

  8. #8
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,027
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you,

    Quote Originally Posted by Aken View Post
    You could also include the space inside the explode() function after the comma.

    Anoox search engine volunteer

    www.anoox.com


Bookmarks

Posting Permissions

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