The Objective
I want to retrieve all the emails between the special characters < >
of the string into an array of emails
我想将字符串的特殊字符<>之间的所有电子邮件检索到电子邮件数组中
$list = '"momo rabit" <m.rabit@sfr.fr>, "youn" <youn@hotmail.fr>, "yourmail" <yourmail@gmail.com>, "yovan" <y.yovan@orange.fr>, "popol" <popol.paul@alice.fr>';
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
我也尝试过没有成功
1 个解决方案
#1
3
The answer is pretty easy. The htmlspecialchars
converts the <
and >
to <
and >
. So either change the regex or remove that function.
答案很简单。 htmlspecialchars将 <和> 转换为<和>。因此,要么更改正则表达式,要么删除该功能。
$list = '"momo rabit" <m.rabit@sfr.fr>, "youn" <youn@hotmail.fr>, "yourmail" <yourmail@gmail.com>, "yovan" <y.yovan@orange.fr>, "popol" <popol.paul@alice.fr>';
//$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" <m.rabit@sfr.fr>, "youn" <youn@hotmail.fr>, "yourmail" <yourmail@gmail.com>, "yovan" <y.yovan@orange.fr>, "popol" <popol.paul@alice.fr>';
$list = htmlspecialchars($list);
preg_match_all("/<(.*?)>/", $list, $list_step);
var_dump($list_step); // Return empty arrays
Demo: https://3v4l.org/gI07A
#1
3
The answer is pretty easy. The htmlspecialchars
converts the <
and >
to <
and >
. So either change the regex or remove that function.
答案很简单。 htmlspecialchars将 <和> 转换为<和>。因此,要么更改正则表达式,要么删除该功能。
$list = '"momo rabit" <m.rabit@sfr.fr>, "youn" <youn@hotmail.fr>, "yourmail" <yourmail@gmail.com>, "yovan" <y.yovan@orange.fr>, "popol" <popol.paul@alice.fr>';
//$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" <m.rabit@sfr.fr>, "youn" <youn@hotmail.fr>, "yourmail" <yourmail@gmail.com>, "yovan" <y.yovan@orange.fr>, "popol" <popol.paul@alice.fr>';
$list = htmlspecialchars($list);
preg_match_all("/<(.*?)>/", $list, $list_step);
var_dump($list_step); // Return empty arrays
Demo: https://3v4l.org/gI07A