如何检查PHP中的重复电子邮件地址,考虑Gmail(user.name+label@gmail.com) [英] How to check for a duplicate email address in PHP, considering Gmail (user.name+label@gmail.com)

查看:902
本文介绍了如何检查PHP中的重复电子邮件地址,考虑Gmail(user.name+label@gmail.com)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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


$ b $尽管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];

这篇关于如何检查PHP中的重复电子邮件地址,考虑Gmail(user.name+label@gmail.com)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆