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

Kri*_*iem 4 php gmail email-validation duplicates detection

如何检查PHP中的重复电子邮件地址,是否有可能使用Gmail的自动贴标机和标点符号?

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

         username@gmail.com
        user.name@gmail.com
   username+label@gmail.com
  user.name+label@gmail.com
Run Code Online (Sandbox Code Playgroud)

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

pow*_*tac 6

$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];
Run Code Online (Sandbox Code Playgroud)

  • 您可能只想从GMail地址中删除".".正如对OP的评论中所提到的,大多数邮件提供商都会认出"." 作为有效字符,使地址不同. (2认同)