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实际上是同一个用户.
$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)