For users privacy we don’t want to display the full email addresses – and we can use the following PHP function to mask the email addresses properly. For example: admin@helloacm.com will be masked into a***n@helloacm.com
Here we only mask the email account name and leave the account domain names intact.
<?php
function maskEmail($x) {
$arr = explode("@", trim($x));
return $arr[0][0] . str_repeat("*", strlen($arr[0]) - 2).$arr[0][count($arr) - 1]. "@" . $arr[1];
}
Assuming the email address given is valid. We should use count to return the length of the array rather than use strlen which works for a string type.
See also: How to Filter the Unique Email Addresses?
–EOF (The Ultimate Computing & Technology Blog) —
Last Post: Teaching Kids Programming - Dynamic Programming or Greedy Algorithm to Compute the Min Change
Next Post: Teaching Kids Programming - Two Pointer Algorithm to Solve Four Sum Problem