Reputation: 1770
The Objective
I want to retrieve all the emails between the special characters < >
of the string into an array of emails
$list = '"momo rabit" <[email protected]>, "youn" <[email protected]>, "yourmail" <[email protected]>, "yovan" <[email protected]>, "popol" <[email protected]>';
What I tried
Based on this answer, it should work.
$list = htmlspecialchars($list);
preg_match_all("/<(.*?)>/", $list, $list_step);
var_dump($list_step); // Return empty arrays
I also tried without success
Upvotes: 1
Views: 309
Reputation: 23880
The answer is pretty easy. The htmlspecialchars
converts the <
and >
to <
and >
. So either change the regex or remove that function.
$list = '"momo rabit" <[email protected]>, "youn" <[email protected]>, "yourmail" <[email protected]>, "yovan" <[email protected]>, "popol" <[email protected]>';
//$list = htmlspecialchars($list);
preg_match_all("/<(.*?)>/", $list, $list_step);
var_dump($list_step); // Return empty arrays
Demo: https://3v4l.org/VUY1U
Alternative:
$list = '"momo rabit" <[email protected]>, "youn" <[email protected]>, "yourmail" <[email protected]>, "yovan" <[email protected]>, "popol" <[email protected]>';
$list = htmlspecialchars($list);
preg_match_all("/<(.*?)>/", $list, $list_step);
var_dump($list_step); // Return empty arrays
Demo: https://3v4l.org/gI07A
Upvotes: 3