This code opens all excel files in a folder then it gets all emails in the file opened and puts them in an array. In the end I need ONE BIG array from all the content from all the array of arrays. I need it to be one big array of all emails from all files.
The code below is not working. I am sure this is a simple one. Thanks
<?
$Folder = "sjc/";
$files = scandir($Folder);
function cleanFolder($file)
{
$string = file_get_contents("sjc/$file");
$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
preg_match_all($pattern, $string, $matches);
$Emails[] = $matches[0];
return $Emails;
}
function beginClean($files)
{
for($i=0; count($files)>$i;$i++)
{
$Emails = cleanFolder("$files[$i]");
$TheEmails .= explode(",",$Emails);
}
/// Supposed to be a big string of emails separated by comma
echo $TheEmails; // But it just echos .... ArrayArrayArrayArrayArray etc...
// WHAT I REALLY WANT IS.. one Array holding all emails, not an Array of Arrays.
}
beginClean($files);
?>
UPDATE: GOT TOT WORK.. HOWEVER I am having a memory issue now as the emails total over 229911.
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /home/public_html/StatuesPlus/CleanListFolder.php on line 33
Here is the code that worked:
<?
$Folder = "sjc/";
$files = scandir($Folder);
function cleanFolder($file)
{
//echo "FILE NAME " . $file . "<br>";
$string = file_get_contents("sjc/$file");
$pattern = '/[a-z0-9_\-\+]+@[a-z0-9\-]+\.([a-z]{2,3})(?:\.[a-z]{2})?/i';
preg_match_all($pattern, $string, $matches);
$TheEmails .= implode(',', $matches[0]);
return $TheEmails;
}
function beginClean($files)
{
for($i=0; count($files)>$i;$i++)
{
$Emails .= cleanFolder("$files[$i]");
}
$TheEmails = explode(",", $Emails);
//$UniqueEmails= array_unique($TheEmails);
echo count($TheEmails);
//file_put_contents("Emails.txt", $TheEmails);
}
beginClean($files);
?>