Hi there,
Try this function:
function extractEmails($string) {
$emails = array();
preg_match_all("/\b\w+\@\w
+[\.\w+]+\
b/", $string, $out);
foreach($out[0] as $email) {
$emails[] = strtolower($email);
}
if (!empty($emails)) {
return $emails;
}
return false;
}
Now to call it - you can use a string:
$content = "some string with
[email protected], and another email
[email protected]";
or use output buffering to get the content from the file:
ob_start();
require_once('file_with_co
ntent.php'
);
$content = ob_get_clean();
then simply call the funciton and pass the $content to it as a parameter:
$emails = extractEmails($content);
Now $emails array stores all email addresses found in the string / or file.
you can print the array to display all these or do whatever you need with it:
echo "<pre>";
print_r($emails);
echo "</pre>";