Skip to content

Instantly share code, notes, and snippets.

@alpha1125
Created August 13, 2020 22:11
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 alpha1125/c0935e9417822a90d6f17592d6a04c50 to your computer and use it in GitHub Desktop.
Save alpha1125/c0935e9417822a90d6f17592d6a04c50 to your computer and use it in GitHub Desktop.
scrap files from a subdirectories, for emails, and echo them out as a CSV.
<?php
$folders = glob("*", GLOB_ONLYDIR);
$emailPattern = "/[A-z0-9._%+-]+@[A-z0-9.-]+\.[A-z]{2,}/";
foreach ($folders as $folder) {
$files = glob("$folder/*.html");
foreach ($files as $file) {
$contents = file_get_contents($file);
echo "$folder,";
if (preg_match($emailPattern, $contents, $matches)) {
echo "$matches[0]";
};
echo PHP_EOL;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment