简体   繁体   English

在PHP中分离多个电子邮件地址

[英]Separating Multiple Email Addresses in PHP

Following this thread: 遵循这个主题:

PHP: Textbox Separate Emails PHP:Textbox单独的电子邮件

I am attempting to separate multiple email addresses that are being entered into a textbox. 我正在尝试将正在输入的多个电子邮件地址分隔到文本框中。 My problem is that if I use the advice from above: 我的问题是如果我使用上面的建议:

$emails = preg_split('/[;,\n]/', $_POST['email_receivers']);

It works great only if there is no space after the delimiter. 只有在分隔符后面没有空格时才能正常工作。 How can I adjust this so that someone can separate email addresses by either just the delimiter or the delimiter plus a space. 我如何调整此值,以便有人可以通过分隔符或分隔符加空格来分隔电子邮件地址。

eg. 例如。 ( email1@xyz.com;email2@xyz.com ) AND ( email1@xyz.com; email2@xyz.com ) should both work but currently only the first example works. email1@xyz.com;email2@xyz.com )和( email1@xyz.com; email2@xyz.com )应该都可以,但目前只有第一个例子有效。

I'd like to improve Michael Berkowski's answer by making the spaces optional: 我想通过使空格可选来改进Michael Berkowski的答案:

$emails = preg_split('/\s*[;,\n]\s*/', $_POST['email_receivers']);

\\s+ requires one or more spaces. \\s+需要一个或多个空格。 \\s* makes them optional (zero or more) \\s*使它们可选(零或更多)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM