[PHP] str_replace around a character??
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 = ema...@domain.com ,ema...@doamin.com,ema...@domain.com , ema...@domain.com, to be $cc = ema...@domain.com, ema...@doamin.com, ema...@domain.com, ema...@domain.com Any pointers would be much appreciated. TIA Best Regards, Karl DeSaulniers Design Drumm http://designdrumm.com
Re: [PHP] str_replace around a character??
On 2011-07-13 09:54, Karl DeSaulniers wrote: $cc = ema...@domain.com ,ema...@doamin.com,ema...@domain.com , ema...@domain.com, $cc = trim($cc,,); $result = preg_replace('/(\s?)(,)(\s?)/i', ',', $cc); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] str_replace around a character??
On Wednesday 13 July 2011 11:09:45 Jay Ess wrote: On 2011-07-13 09:54, Karl DeSaulniers wrote: $cc = ema...@domain.com ,ema...@doamin.com,ema...@domain.com , ema...@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 strper...@example.com -- Vitalii -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] str_replace around a character??
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 = ema...@domain.com ,ema...@doamin.com,ema...@domain.com , ema...@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 namestrper...@example.com That was never the requirement ;) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] str_replace around a character??
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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php