How To Replace Some Character In Email With (*) Using PHP

Sometimes for security reasons, we can’t display the full email on the page.

To Overcome this situation, We can replace Some Email characters with another sign.

Here is the code for adding another sign in the Email character.

We can use any sign for this; in this case, I used (*).

Add this code where you want to display Email.

$original_email = "";
$explode_email = explode( "@", $original_email );
$explode_email_character = substr( $explode_email[0], 1 );
$explode_email_first_character = substr( $explode_email[0], 0, 1);  // first world
$email_character_length = strlen( $explode_email_character );
$add_star = '';
for( $i=0; $i<=$email_character_length; $i++ ){
    $add_star .= '*';
$final_email = $explode_email_first_character . $add_star . '@' . $explode_email[1];

<h6>Original Email</h6>
<h6>After apply (*) in Email</h6>
<p><?php echo $final_email; ?></p>

Here is the Output:

Submit a Comment

Your email address will not be published. Required fields are marked *


Select Categories