Skip to content

Instantly share code, notes, and snippets.

@NimaGhaedsharafi
Created May 25, 2017 18:03
Show Gist options
  • Save NimaGhaedsharafi/17547c35364896828cf03a26c1f15ec6 to your computer and use it in GitHub Desktop.
Save NimaGhaedsharafi/17547c35364896828cf03a26c1f15ec6 to your computer and use it in GitHub Desktop.
Normalize Email
/**
* @param $email
* @return string
*/
public function normaliseEmail($email)
{
if (ends_with($email, 'gmail.com')) {
$segments = explode('@', $email);
// hmm, we just need the part before + sign!
$beforePlus = strstr($segments[0], '+', true);
$beforeAt = $beforePlus ? $beforePlus : $segments[0];
// let's check for periods! we don't need them too.
$beforeAt = str_replace('.', '', $beforeAt);
// let's concat them again.
$email = $beforeAt . '@' . $segments[1];
}
return strtolower($email);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment