php将一个数组变成字符串,PHP将数组数组转换为一个字符串或一个大数组

此代码将打开文件夹中的所有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 . "
";

$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));

标签:loops,arrays,php

来源: https://codeday.me/bug/20191123/2066357.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值