3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function maskString($string) { return preg_replace('/(?<=.).(?=.*)/u','*',$string); } function maskEmail($email) { $arremail = explode('@',$email); $arrdomain = explode('.',$arremail[1]); $jumdomain = count($arrdomain); echo $jumdomain; $dom = array(); for($i=0; $i<$jumdomain-1; $i++) { $dom[] = maskString($jumdomain[$i]); } $domain = implode('.',$dom); //$email1 = preg_replace('/(?<=.).(?=.*@)/u','*',$arremail[0].'@'); //$email2 = preg_replace('/(?<=.).(?=.*[.])/u','*',$arremail[1]); //return $email1.$email2; return maskString($arremail[0]).'@'.$domain; } $email = 'facebook@yahoo.co.id'; $result = maskEmail($email); echo $result;
based on DotQC
Output for 4.3.0 - 7.2.0
3f*******@.