How to show only some part of Email

Often we see that Email Address on websites are not shown completely but only first few characters are shown i.e. before @ part, 1 character after @ and last few characters of email address.
It is used so that user (whose email id we are displaying) can recall what email address he has used. So, this is how we can do it:
[php]<?php
$usreml="[email protected]";

$usreml_parts=explode(‘@’,$usreml);
$usreml_sub1=substr($usreml_parts[0],0,2);
$usreml_sub2=substr($usreml_parts[1],0,1);
$usreml_sub3=substr($usreml_parts[1],-2,2);

$usreml_sub1_len=strlen($usreml_parts[0]);
$usreml_sub2_len=strlen($usreml_parts[1]);

for($i_strlen=0; $i_strlen<($usreml_sub1_len-2); $i_strlen++)
{
$usreml_sub1_hidden=$usreml_sub1_hidden."*";
}

for($i_strlen=0; $i_strlen<($usreml_sub2_len-3); $i_strlen++)
{
$usreml_sub2_hidden=$usreml_sub2_hidden."*";
}

$usreml_sub=$usreml_sub1.$usreml_sub1_hidden."@".$usreml_sub2.$usreml_sub2_hidden.$usreml_sub3;
echo "$usreml_sub";
?>

[/php]

Leave a Comment