首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >删除基于域的重复电子邮件地址

删除基于域的重复电子邮件地址
EN

Stack Overflow用户
提问于 2022-01-13 23:51:54
回答 1查看 86关注 0票数 0

我想删除重复的电子邮件地址基础上的域名。例如:

代码语言:javascript
复制
aa@example.com
bb@example.com
cc@bla.com

Should become:

aa@example.com
cc@bla.com

有人能帮忙吗?我试过使用sort / uniq和awk,但还没有让它正常工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-14 00:09:57

在php中:

代码语言:javascript
复制
<?php
$domains   = []; // list of domains we have already included
$cleanList = []; // "clean" email list
$list      = file('/path/to/email-list.txt'); // load the raw list

// loop over the raw list
foreach($list as $email) {
   // extract the domain from the email
   $domain = preg_replace('/^.*@/', '', $email);

   // if the domain has not been taken yet
   if(!in_array($domain, $domains)) {
      // add it to the list of taken domains
      array_push($domains, $domain);

      // add the email to the clean list
      array_push($cleanList, $email);
   }
}

// write the clean list out to a file
file_put_contents('/tmp/clean-emails.txt', implode("\n", $cleanList));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70704509

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档