EmailObfuscator.php
625 Bytes
<?php
namespace FootyRoom\Support\Utils;
class EmailObfuscator
{
/**
* Obfuscates given email address.
*
* @param string $email
*
* @return string
*/
public static function obfuscate($email)
{
$chars = str_split($email);
$hiddenEmail = [];
for ($i = 0; $i < count($chars); $i++) {
if ($i < 1 || $i+5 >= count($chars) || $chars[$i+1] == '@' || $chars[$i] == '@') {
$hiddenEmail[] = $chars[$i];
} else {
$hiddenEmail[] = '*';
}
}
return implode('', $hiddenEmail);
}
}