Php Programming Code Examples
Php > E-Mail Code Examples
Get Email Addresses from Strings
Get Email Addresses from Strings
<?php
function get_emails ($str)
{
$emails = array();
preg_match_all("/\b\w+\@\w+[\.\w+]+\b/", $str, $output);
foreach($output[0] as $email) array_push ($emails, strtolower($email));
if (count ($emails) >= 1) return $emails;
else return false;
}
# Here is how to use it.
# Sample string containing email addresses;
$str = "test [email protected] ha ha [email protected] bla bla [email protected]";
# Get the emails on arrays;
$emails = get_emails ($str);
# Print that arrays;
print_r ($emails);
?>