Skip to content

Instantly share code, notes, and snippets.

@bradleyhodges
Created May 2, 2017 08:30
Show Gist options
  • Save bradleyhodges/f637b68a8cffd0911f7a2c2d6779ee27 to your computer and use it in GitHub Desktop.
Save bradleyhodges/f637b68a8cffd0911f7a2c2d6779ee27 to your computer and use it in GitHub Desktop.
PHP Email Protector
function protectEmail($email) {
$suffix = substr($email, strpos($email, "@") + 1);
$email = str_replace($suffix, "", $email);
$email = str_replace("@", "", $email);
if (strlen($email) > 3) {
$f3c = mb_substr($email, 0, 3);
$rlength = (strlen($email) - 3);
$email = $f3c . str_repeat("*", $rlength);
return $email . "@" . $suffix;
} else {
return $email;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment