我如何解析这种格式的电子邮件地址:
"Bob Smith" <bob@company.com>, joe@company.com, "John Doe"<john@company.com>
得到这样的数组:
array(
'bob@company.com'=>'Bob Smith'
'joe@company.com'=>''
'john@company.com'=>'John Doe'
);
我们和Laravel有类似mailparse_rfc822_parse_addresses()的内容吗?
答案 0 :(得分:0)
您可以使用此功能从字符串中提取所有电子邮件:
function extract_email_address_from_string ($string) {
foreach(preg_split('/\s/', $string) as $token) {
$email = filter_var(filter_var($token, FILTER_SANITIZE_EMAIL), FILTER_VALIDATE_EMAIL);
if ($email !== false) {
$emails[] = $email;
}
}
return $emails;
}