FAQ
Hello All,
I am needing some assistance. I am trying to add some Cc and Bcc to a
mail script I have.
On the form I have instructions for each to be separated by a comma +
a space.
In an all perfect world each user would do this perfectly. ...but
since were working with something different,
how can I check for this? and catch any that dont do this perfectly?

Is there a reg exp that covers this? I have seen many, but some make
the head cramp. Mi mui novicio.
To wrap it up, I am basically trying to do this...

$cc = "email1@domain.com ,email2@doamin.com,email3@domain.com ,
email4@domain.com, "

to be

$cc = "email1@domain.com, email2@doamin.com, email3@domain.com,
email4@domain.com"

Any pointers would be much appreciated.
TIA
Best Regards,

Karl DeSaulniers
Design Drumm
http://designdrumm.com

Search Discussions

  • Jay Ess at Jul 13, 2011 at 8:09 am

    On 2011-07-13 09:54, Karl DeSaulniers wrote:
    $cc = "email1@domain.com ,email2@doamin.com,email3@domain.com ,
    email4@domain.com, "
    $cc = trim($cc,",");
    $result = preg_replace('/(\s?)(,)(\s?)/i', ',', $cc);
  • Vitalii Demianets at Jul 13, 2011 at 8:36 am

    On Wednesday 13 July 2011 11:09:45 Jay Ess wrote:
    On 2011-07-13 09:54, Karl DeSaulniers wrote:
    $cc = "email1@domain.com ,email2@doamin.com,email3@domain.com ,
    email4@domain.com, "
    $cc = trim($cc,",");
    $result = preg_replace('/(\s?)(,)(\s?)/i', ',', $cc);
    The solution is broken because of:
    1) you have missed spaces after comma in two places. It should be like this:
    $cc = trim($cc,", "); // <- here space after comma in the second argument
    $result = preg_replace('/(\s?)(,)(\s?)/i', ', ', $cc); // <-- the same, here
    space after comma in replacement string.

    2) it doesn't work with address lines like this:

    To: "Some strange ,, person name" <strperson@example.com>

    --
    Vitalii
  • Jay Ess at Jul 13, 2011 at 8:43 am

    On 2011-07-13 10:36, Vitalii Demianets wrote:
    On Wednesday 13 July 2011 11:09:45 Jay Ess wrote:
    On 2011-07-13 09:54, Karl DeSaulniers wrote:
    $cc = "email1@domain.com ,email2@doamin.com,email3@domain.com ,
    email4@domain.com, "
    $cc = trim($cc,",");
    $result = preg_replace('/(\s?)(,)(\s?)/i', ',', $cc);
    The solution is broken because of:
    1) you have missed spaces after comma in two places. It should be like this:
    $cc = trim($cc,", "); //<- here space after comma in the second argument
    $result = preg_replace('/(\s?)(,)(\s?)/i', ', ', $cc); //<-- the same, here
    space after comma in replacement string.
    Yes, that was pretty sloppy of me hehe.
    2) it doesn't work with address lines like this:

    To: "Some strange ,, person name"<strperson@example.com>
    That was never the requirement ;)
  • Shiplu Mokaddim at Jul 13, 2011 at 10:03 am
    If you are looking for a one liner reg ex, it may take some time. This may lead wasting your development time. Better you do the following,

    1. replace the string with tokens in address.
    2. Split using comma.
    3. Apply common email regex.
    4. Replace tokens with actual strings.
    5. Rebuild/join the string with ", "

    With this approach you can validate individual emails too.


    Sent from a handheld device
  • Shawn McKenzie at Jul 13, 2011 at 2:59 pm

    On 07/13/2011 02:54 AM, Karl DeSaulniers wrote:
    Hello All,
    I am needing some assistance. I am trying to add some Cc and Bcc to a
    mail script I have.
    On the form I have instructions for each to be separated by a comma + a
    space.
    In an all perfect world each user would do this perfectly. ...but since
    were working with something different,
    how can I check for this? and catch any that dont do this perfectly?

    Is there a reg exp that covers this? I have seen many, but some make the
    head cramp. Mi mui novicio.
    To wrap it up, I am basically trying to do this...

    $cc = "email1@domain.com ,email2@doamin.com,email3@domain.com ,
    email4@domain.com, "

    to be

    $cc = "email1@domain.com, email2@doamin.com, email3@domain.com,
    email4@domain.com"

    Any pointers would be much appreciated.
    TIA
    Best Regards,

    Karl DeSaulniers
    Design Drumm
    http://designdrumm.com
    $cc = implode(', ', array_filter(array_map('trim', explode(',', $cc))));

    --
    Thanks!
    -Shawn
    http://www.spidean.com
  • Florian Lemaitre at Jul 13, 2011 at 4:09 pm

    Le 13/07/2011 16:59, Shawn McKenzie a écrit :
    On 07/13/2011 02:54 AM, Karl DeSaulniers wrote:
    Hello All,
    I am needing some assistance. I am trying to add some Cc and Bcc to a
    mail script I have.
    On the form I have instructions for each to be separated by a comma + a
    space.
    In an all perfect world each user would do this perfectly. ...but since
    were working with something different,
    how can I check for this? and catch any that dont do this perfectly?

    Is there a reg exp that covers this? I have seen many, but some make the
    head cramp. Mi mui novicio.
    To wrap it up, I am basically trying to do this...

    $cc = "email1@domain.com ,email2@doamin.com,email3@domain.com ,
    email4@domain.com, "

    to be

    $cc = "email1@domain.com, email2@doamin.com, email3@domain.com,
    email4@domain.com"

    Any pointers would be much appreciated.
    TIA
    Best Regards,

    Karl DeSaulniers
    Design Drumm
    http://designdrumm.com
    $cc = implode(', ', array_filter(array_map('trim', explode(',', $cc))));
    This should work just fine ;).

    $cc = implode(', ', array_filter(filter_var_array(array_map('trim',
    explode(',', $cc)), FILTER_VALIDATE_EMAIL)));
  • Karl DeSaulniers at Jul 13, 2011 at 9:03 pm

    On Jul 13, 2011, at 9:59 AM, Shawn McKenzie wrote:
    On 07/13/2011 02:54 AM, Karl DeSaulniers wrote:
    Hello All,
    I am needing some assistance. I am trying to add some Cc and Bcc to a
    mail script I have.
    On the form I have instructions for each to be separated by a
    comma + a
    space.
    In an all perfect world each user would do this perfectly. ...but
    since
    were working with something different,
    how can I check for this? and catch any that dont do this perfectly?

    Is there a reg exp that covers this? I have seen many, but some
    make the
    head cramp. Mi mui novicio.
    To wrap it up, I am basically trying to do this...

    $cc = "email1@domain.com ,email2@doamin.com,email3@domain.com ,
    email4@domain.com, "

    to be

    $cc = "email1@domain.com, email2@doamin.com, email3@domain.com,
    email4@domain.com"

    Any pointers would be much appreciated.
    TIA
    Best Regards,

    Karl DeSaulniers
    Design Drumm
    http://designdrumm.com
    $cc = implode(', ', array_filter(array_map('trim', explode(',',
    $cc))));

    --
    Thanks!
    -Shawn
    http://www.spidean.com

    Thanks Shawn,
    I had actually found the same thing myself..

    $subCc = array_map('trim',explode(",",$subCc));

    But I could not find my post last night to make a new comment about it.
    Thank you for yours though.. I did not think of the implode part.

    Best,

    Karl DeSaulniers
    Design Drumm
    http://designdrumm.com
  • Shawn McKenzie at Jul 14, 2011 at 10:27 pm

    On 07/13/2011 04:03 PM, Karl DeSaulniers wrote:

    Thanks Shawn,
    I had actually found the same thing myself..

    $subCc = array_map('trim',explode(",",$subCc));

    But I could not find my post last night to make a new comment about it.
    Thank you for yours though.. I did not think of the implode part.

    Best,

    Karl DeSaulniers
    Design Drumm
    http://designdrumm.com
    You probably want the array_filter() in there also, because commas at
    the beginning or end or other issues can leave you with empty array
    elements that will still be imploded resulting in just a comma.

    --
    Thanks!
    -Shawn
    http://www.spidean.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-general @
categoriesphp
postedJul 13, '11 at 7:54a
activeJul 14, '11 at 10:27p
posts9
users6
websitephp.net

People

Translate

site design / logo © 2022 Grokbase