醉菜鸟 2021-08-01 12:39:07

php 以星号隐藏邮箱

/**
* 隐藏部分字符串后的邮箱地址
* @param string $mail
* @return string
*/
function hidden_mail($mail)
{
if (!preg_match("/^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{2,30}$/i", $mail)) {
return '';
}
$email_array = explode("@", $mail);
$prefix = (strlen($email_array[0]) < 3) ? $email_array[0] : substr($mail, 0, 2);
$mail = preg_replace('/([\d\w+_-]{0,100})@/', '***@', $mail, -1);
return $prefix.$mail;
}
意见反馈