ItSolutionStuff.com

How to Partially Hide Email Address in PHP?

By Hardik Savani • May 14, 2024
PHP

Here, i will let you know partially hide email address using php. we can hide email address as like hardik******@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.

I 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:

PHP Code:

<?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 = "itsolutionstuff@gmail.com";

echo hideEmailAddress($email);

?>

Output:

its************@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 = 'itsolutionstuff@gmail.com';

echo hideEmailAddress($email);

?>

Output:

itsolut*******@gmail.com

I hope it can help you...

Tags: PHP
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

PHP - How to Reindex Array Key After Unset Key?

Read Now →

PHP JQuery Ajax Post Request Example

Read Now →

PHP Array Remove Keys and Keep Values Example

Read Now →

PHP Dropzone Display Existing Files from Server Example

Read Now →

PHP Ajax Drag and Drop Sorting Table Rows Example

Read Now →

How to Make Read More Link from String in PHP?

Read Now →

PHP Bootstrap Autocomplete Tokenfield using Ajax Example

Read Now →

PHP MySQL Highcharts Chart Example

Read Now →

Multiple File Upload using Dropzone JS in PHP Example

Read Now →

Convert HTML to PDF in PHP with Dompdf Example

Read Now →

PHP Capture Screenshot of Website from URL Example

Read Now →

How to Get Folder Path from File Path in PHP?

Read Now →

PHP Check Word Exist in String or Not Example

Read Now →

How to Get a Current Page URL in PHP?

Read Now →