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 wan
This answer is an improvement on @powtac's answer. I needed this function to defeat multiple signups from same person using gmail.
if ( ! function_exists('normalize_email'))
{
/**
* to normalize emails to a base format, especially for gmail
* @param $email
* @return string
*/
function normalize_email($email) {
// ensure email is lowercase because of pending in_array check, and more...
$email = strtolower($email);
$parts = explode('@', $email);
// normalize gmail addresses
if (in_array($parts[1], ['gmail.com', 'googlemail.com'])) {
// check if there is a "+" and return the string before then remove "."
$before_plus = strstr($parts[0], '+', TRUE);
$before_at = str_replace('.', '', $before_plus ? $before_plus : $parts[0]);
// ensure only @gmail.com addresses are used
$email = $before_at.'@gmail.com';
}
return $email;
}
}