In this tutorial, We will learn how to partially hide email addresses using PHP. For example: rat******@g***.com.
Example:
<?php
function hideEmailAddress($email)
{
if(filter_var($email, FILTER_VALIDATE_EMAIL))
{
list($first, $last) = explode('@', $email);
$first = str_replace(substr($first, '3'), str_repeat('*', strlen($first)-3), $first);
$last = explode('.', $last);
$last_domain = str_replace(substr($last['0'], '1'), str_repeat('*', strlen($last['0'])-1), $last['0']);
$hideEmailAddress = $first.'@'.$last_domain.'.'.$last['1'];
return $hideEmailAddress;
}
}
$email = "gajanand.kgn@gmail.com";
echo hideEmailAddress($email);
?>
Output:
gaja*********@g****.com |
Thanks, I hope it will help you....