考虑到 Gmail (user.name+label@gmail.com),如何在 PHP 中检查重复的电子邮件地址

如何在 PHP 中检查重复的电子邮件地址,并考虑到 Gmail 的自动标记器和标点符号?

How can I check for duplicate email addresses in PHP, with the possibility of Gmail's automated labeler and punctuation in mind?

例如,我希望将这些地址检测为重复:

For example, I want these addressed to be detected as duplicates:

         username@gmail.com
        user.name@gmail.com
   username+label@gmail.com
  user.name+label@gmail.com

尽管 Daniel A. White 声称:在 Gmail 中,@"(和标签)之前随机位置的点可以随意放置.user.name@gmail.com 和 username@gmail.com 实际上是同一个用户.

Despite what Daniel A. White claims: In Gmail, dots at random places before the '@' (and label) can be placed as much as you like. user.name@gmail.com and username@gmail.com are in fact the same user.

推荐答案

$email_parts    = explode('@', $email);

// check if there is a "+" and return the string before
$before_plus    = strstr($email_parts[0], '+', TRUE);
$before_at      = $before_plus ? $before_plus : $email_parts[0];

// remove "."
$before_at      = str_replace('.', '', $before_at);

$email_clean    = $before_at.'@'.$email_parts[1];

相关文章