Skip to content

Instantly share code, notes, and snippets.

@pendexgabo
Last active December 23, 2015 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pendexgabo/6689723 to your computer and use it in GitHub Desktop.
Save pendexgabo/6689723 to your computer and use it in GitHub Desktop.
stripped down function to get emails from text files. Source: squirrelmail-webmail-1.4.22 functions/url_parser.php
<?php
function parse_emails ($text) {
$IP_RegExp_Match = '\\[?[0-9]{1,3}(\\.[0-9]{1,3}){3}\\]?';
$Host_RegExp_Match = '(' . $IP_RegExp_Match . '|[0-9a-z]([-.]?[0-9a-z])*\\.[a-z][a-z]+)';
$Email_RegExp_Match = '[0-9a-z]([-_.+]?[0-9a-z])*(%' . $Host_RegExp_Match . ')?@' . $Host_RegExp_Match;
preg_match_all('/'.$Email_RegExp_Match.'/i', $text, $regs);
$addresses = array_merge(array_unique($regs[0]));
return $addresses;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment