i have a form where user can either input email ids like
开发者_如何学Csomeone@somewhere.com,anyone@anywhere.com
OR
someone@somewhere.com anyone@anywhere.com
I'm using PHP for scripting i would like to have the email ids extracted!
I'm expecting some cool solutions.
You could use preg_split(), but to be honest, the simplest solution would be to convert all spaces to commas (or vice versa) and then explode by that.
$emails = explode(",", str_replace(" ", ",", $email_string));
Hi guys thanks for your patient and speedy replies but i found out a way i'll accept this only when you confirm it has no bugs.ie no replies for a day
<?php
$keywords = preg_split("/[\s,]+/",
"someone@somewhere.com,anyone@anywhere.com,",-1,PREG_SPLIT_NO_EMPTY);
print_r($keywords);
?>
OUTPUT
Array
(
[0] => someone@somewhere.com
[1] => anyone@anywhere.com
)
it was omitting even the extra comma at the end. even if i added more space waiting for your replies!
$input = "someone@somewhere.com,anyone@anywhere.com";
$emails = explode(",", $input);
if(count($emails) == 1) {
$emails = explode(" ", $input);
}
print_r($emails);
/* output:
Array
(
[0] => someone@somewhere.com
[1] => anyone@anywhere.com
)
*/
精彩评论