I need to split this kind of strings to separate the email between less and greater than < >. Im trying with the next regex and preg_split, but I does not works.
"email1@domain.com" <email1@domain.com>
News <news@e.domain.com>
Some Stuff <email-noreply@somestuff.com>
The expected result will be:
Array
(
[0] => "email1@domain.com"
[1] => email@email.com
)
Array
(
[0] => News
[1] => news@e.domain.com
)
Array
(
[0] => Some Stuff
[1] => email-noreply@somestuff.com
)
Code that I am using now:
foreach ($emails as $email)
{
$pattern = '/<(.*?)>/';
$result = preg_split($pattern, $email);
print_r($result);
}
You may use some of the flags available for
preg_split:PREG_SPLIT_DELIM_CAPTUREandPREG_SPLIT_NO_EMPTY.This outputs what you expect: