使用引号中的逗号分隔逗号分隔的字符串中的电子邮件地址

Say I have the following email addresses comma separated in a string:

$addrList = 'Kevin.Brine@pppg.com, Robert.Thomas@pppg.com, "Guice, Doug" <Doug.Guice@pppg.com>';

I need the following result:

[0] => Kevin.Brine@pppg.com
[1] => Robert.Thomas@pppg.com
[2] => "Guice, Doug" <Doug.Guice@pppg.com>

Seems fairly simple, but that comma in the quoted name really has thrown me in trying to find a solution using either preg_match_all or preg_split. Also we should accommodate for emails that use single quotes for names too, ie: 'smith, tom' <tom.smith@abc.com>

str_getcsv() should give you what you need, though it will strip the quotes.

EDIT

If you want to put the quotes back in:

$addrList = 'Kevin.Brine@pppg.com, Robert.Thomas@pppg.com, "Guice, Doug" <Doug.Guice@pppg.com>';


$t = str_getcsv($addrList);

foreach($t as $k => $v) {
    if (strpos($v,',') !== false) {
        $t[$k] = '"'.str_replace(' <','" <',$v);
    }
}

var_dump($t);