PHP Partially Hide Email Address Example
Hi Guys,
Today, I will learn you how to Partially hide email address in PHP.we can hide email address as like dharmik******@g***.com. you will learn How to Partially hide email address in PHP?.
As you notice on facebook, google etc social media, when you forgot password then they will show you partially hide email address so use can know what is my email connected with this account same thing i will give you simple example of How to Partially hide email address in PHP, So you can easily use with your php application.
We will give you two example and also show you a output so you can use anyone as you want. we need to create php functions and you can simple call it with argument.
Example 1:
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 = "[email protected]";
echo hideEmailAddress($email);
?>
Output:
nic*********@g****.com
Example 2:
PHP Code:
<?php
function hideEmailAddress($email)
{
$em = explode("@",$email);
$name = implode(array_slice($em, 0, count($em)-1), '@');
$len = floor(strlen($name)/2);
return substr($name,0, $len) . str_repeat('*', $len) . "@" . end($em);
}
$email = '[email protected]';
echo hideEmailAddress($email);
?>
Output
nicesn******@gmail.com
It will help you...
- How To Use Php Conditional Statement Example
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example