Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for a duplicate email address in PHP, considering Gmail ([email protected])

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:

         [email protected]
        [email protected]
   [email protected]
  [email protected]

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

like image 537
Kriem Avatar asked Dec 18 '22 05:12

Kriem


1 Answers

$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];
like image 86
powtac Avatar answered Dec 28 '22 08:12

powtac