Im trying to achieve the following with PHP
sample@gmail.com => s*****@gmail.com
sa@yahoo.com => **@yahoo.com
sampleaddress@hotmail.com => samplead*****@hotmail.com
I want to hide last five characters in the portion that stays before '@'
I can write long code to do this by splitting and then replacing based on lengths, but Im sure there must be an easy way to do this using PHP functions, any help please?
UPDATE:
Im adding my code here, Im sure its not efficient, and thats the reason Im asking it here
$email = 'sampleuser@gmail.com';
$star_string = '';
$expl_set = explode('@',$email);
if(strlen ($expl_set[0]) > 5){$no_stars = 5; }else{$no_stars = strlen ($expl_set[0]); }
for($i=0;$i<$no_stars; $i++)
{
$star_string.='*';
}
$masked_email = substr($expl_set[0], 0, -5).$star_string.'@'.$expl_set[1];