php隐藏三个字名字中间一个字,隐藏两个字名字最后一位
php隐藏名字中间,或者后一个字,显示星号public function userNameCut($user_name, $repeatStr = '*', $encode = 'utf-8')
{
if (empty($user_name)) {
return '***';
}
$length = mb_strlen($user_name, $encode);
$firstStr = mb_substr($user_name, 0, 1, $encode);
$lastStr = mb_substr($user_name, -1, 1, $encode);
if($length ==1){
return $user_name;
}
return $length == 2 ? $firstStr . str_repeat($repeatStr, $length - 1) : $firstStr . str_repeat($repeatStr, $length - 2) . $lastStr;
}
然后直接调用这个函数,名字传入第1个参数就可以了