Re: str_replace around a character??

From: Date: Wed, 13 Jul 2011 08:43:06 +0000
Subject: Re: str_replace around a character??
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-314034@lists.php.net to get a copy of this message
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 ;)


« previous php.general (#314034) next »