Re: str_replace around a character??

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wednesday 13 July 2011 11:09:45 Jay Ess wrote:
> On 2011-07-13 09:54, Karl DeSaulniers wrote:
> > $cc = "email1@xxxxxxxxxx ,email2@xxxxxxxxxx,email3@xxxxxxxxxx ,
> > email4@xxxxxxxxxx, "
>
> $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@xxxxxxxxxxx>

-- 
Vitalii

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux