Created
November 15, 2017 14:07
-
-
Save AnandChowdhary/991605fa04f55e7121dfc5932809471b to your computer and use it in GitHub Desktop.
PHP function to obfuscate email
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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