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