此代码将打开文件夹中的所有excel文件,然后将其打开的所有电子邮件都放入一个数组中.最后,我需要一个来自所有数组数组中所有内容的BIG数组.我需要它成为所有文件中所有电子邮件的一大数组.
下面的代码不起作用.我相信这很简单.谢谢
<?
$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);
?>
更新:GOT TOT WORK ..但是我现在遇到了内存问题,因为电子邮件总数超过229911.
致命错误:在第33行的/home/public_html/StatuesPlus/CleanListFolder.php中,耗尽了67108864字节的允许内存大小(试图分配71字节).
这是起作用的代码:
<?
$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);
?>
解决方法:
.=用于连接字符串,而不是数组.但是您可以将它们作为字符串保留一段时间:
$TheEmails .= ",$Emails";
接着:
$TheEmails = explode(',', substr($TheEmails, 1));