How to Partially hide email address using PHP

In this tutorial i will show you how to partially hide email address using php. Many php project need this type speciality. like I want to display email from database and I want to only show some character not a all. You may also like How to Partially hiding an email address using PHP regex.

PHP Code

<?php
    function partially_email($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 = 'youremailaddress@gmail.com';
    echo partially_email($email);
?>

Output

youremai******@gmail.com

And if you like this tutorials please share it with your friends via Email or Social Media.

Leave a Reply

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