Array (
[0] => [email protected]
[1] => [email protected]
[2] => invalidEmail.com
)
Notice that the third array value is invalid email format. How do I remove it by using/creating a function? I need the valid email to implode("," the valid email) before sending an email using the mail() function.
$valid = array_filter($emails, create_function('$s', 'return filter_var($s, FILTER_VALIDATE_EMAIL);'));
Or for PHP 5.3+:
$valid = array_filter($emails, function ($s) { return filter_var($s, FILTER_VALIDATE_EMAIL); });
<?php
$len=count($array);
for ($i=0;$i<$len;$i++)
if (preg_match('^[a-z0-9!#$%&*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+(?:[a-z]{2,4}|museum|travel)$/i',$array[$i]))
echo $array[$i];
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With