Skip to content

Instantly share code, notes, and snippets.

@AnandChowdhary
Created November 15, 2017 14:07
Show Gist options
  • Save AnandChowdhary/991605fa04f55e7121dfc5932809471b to your computer and use it in GitHub Desktop.
Save AnandChowdhary/991605fa04f55e7121dfc5932809471b to your computer and use it in GitHub Desktop.
PHP function to obfuscate email
<?php
function hideEmail($email) {
$email = explode("@", $email);
$name = $email[0];
if (strlen($name) > 3) {
$name = substr($name, 0, 2);
for ($i = 0; $i < strlen($email[0]) - 3; $i++) {
$name .= "*";
}
$name .= substr($email[0], -1, 1);
}
$host = explode(".", $email[1])[0];
if (strlen($host) > 3) {
$host = substr($host, 0, 1);
for ($i = 0; $i < strlen(explode(".", $email[1])[0]) - 2; $i++) {
$host .= "*";
}
$host .= substr(explode(".", $email[1])[0], -1, 1);
}
$email = $name . "@" . $host . "." . explode(".", $email[1])[1];
return $email;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment