Skip to content

Instantly share code, notes, and snippets.

@elliotboney
Created June 24, 2014 01:28
Show Gist options
  • Save elliotboney/ef26f386d2dd5c54bcb2 to your computer and use it in GitHub Desktop.
Save elliotboney/ef26f386d2dd5c54bcb2 to your computer and use it in GitHub Desktop.
Grab emails from a string
<?php
function extract_emails_from($string){
preg_match_all("/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $string, $matches);
return $matches[0];
}
// Example useage
$text = "blah blah blah email@address.com blah blah blah email2@address.com";
$emails = extract_emails_from($text);
print(implode("\n", $emails));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment