我必须从以下字符串中提取电子邮件的一个组成部分:PHP提取字符串
$string = 'other_text_here to=<[email protected]> other_text_here <[email protected]> other_text_here';
服务器发送我的日志,并在那里,我有这种格式的,我怎么能得到的电子邮件进入没有“到= <”和“>”变量?
更新:我已经更新了这个问题,好像这个电子邮件可以在字符串中找到很多次,并且正常的表达式不能很好地与它一起工作。
if (preg_match_all('/<(.*?)>/', $string, $emails)) {
array_shift($emails); // Take the first match (the whole string) off the array
}
// $emails is now an array of emails if any exist in the string
括号告诉它捕捉到了$matches
数组:如果您确信<
和>
字符串中,不使用其他任何地方
它不会让我接受answere,但我会尽快完成,thx –
啊,是的好赶上。固定! –
我已经更新了这个问题,我发现服务器可以多次打印到该电子邮件的日志中,并且正常的表达式在这种情况下效果不佳。 –