PHP:Textbox单独发送电子邮件
如果我有一个文本框,用户可以在其中输入多封电子邮件,即PHP:Textbox单独发送电子邮件,php,email,Php,Email,如果我有一个文本框,用户可以在其中输入多封电子邮件,即 test@test.com test2@test2.com email3@email3.com 如何使用PHP将每封电子邮件分隔成一个数组/对象 是否可以给用户以“;”分隔的选项或“,”或新行?如果给用户一个分隔符,则可以使用。例如,使用: $emails = explode(';', $_GET['emails']); 您可以使用、或\n(新行)代替如果您愿意 如果要基于所有这些字符分割字符串,请使用: 例如: <?php $
test@test.com
test2@test2.com
email3@email3.com
如何使用PHP将每封电子邮件分隔成一个数组/对象
是否可以给用户以“;”分隔的选项或“,”或新行?如果给用户一个分隔符,则可以使用。例如,使用
代码>:
$emails = explode(';', $_GET['emails']);
您可以使用、
或\n
(新行)代替代码>如果您愿意
如果要基于所有这些字符分割字符串,请使用:
例如:
<?php
$emails = 'test@test.com;test2@test2.com
email3@email3.com,email4@email4.com';
$emails = preg_split('/[,;\n]/', $emails);
print_r($emails);
/*
Array
(
[0] => test@test.com
[1] => test2@test2.com
[2] => email3@email3.com
[3] => email4@email4.com
)
*/
<?php
$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str, 2));
// negative limit (since PHP 5.1)
print_r(explode('|', $str, -1));
?>
您可以使用空格或斜杠等分隔符,然后在PHP端使用分解函数PHP.net/explode对其进行拆分。使用explode()返回字符串数组,每个字符串都是字符串的子字符串,通过在字符串分隔符形成的边界上对其进行拆分而形成
array explode ( string $delimiter , string $string [, int $limit ] )
例如:
<?php
$emails = 'test@test.com;test2@test2.com
email3@email3.com,email4@email4.com';
$emails = preg_split('/[,;\n]/', $emails);
print_r($emails);
/*
Array
(
[0] => test@test.com
[1] => test2@test2.com
[2] => email3@email3.com
[3] => email4@email4.com
)
*/
<?php
$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str, 2));
// negative limit (since PHP 5.1)
print_r(explode('|', $str, -1));
?>
更新:
如果要按分隔符数组进行拆分,则需要与相应的正则表达式一起使用。如果|不是唯一的分隔符怎么办?例如,新行、逗号、分号?然后需要使用更复杂的表达式,如preg_match_all。