feat(statistics): 修改IndexController以隐藏用户昵称中间部分

This commit is contained in:
mkm 2024-07-18 18:30:32 +08:00
parent 655252803b
commit 3387dae2b3

View File

@ -144,7 +144,8 @@ class IndexController extends BaseLikeController
if ($item['nickname'] == '') {
$item['nickname'] = $find['nickname'] ?? '';
} else {
$item['nickname']=substr($item['nickname'], 0, 1) . str_repeat('*', strlen($item['nickname']) - (1 + 2)) . substr($item['nickname'], -2);
$nickname=$item['nickname'];
$item['nickname']=$this->hideMiddleName($nickname);
}
} else {
$item['nickname'] = '';
@ -278,4 +279,17 @@ class IndexController extends BaseLikeController
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d", time());
}
}
function hideMiddleName($name) {
$strlen = mb_strlen($name); // 获取字符串长度
$firstStr = mb_substr($name, 0, 1); // 获取名字的第一个字符
$lastStr = mb_substr($name, -1, 1); // 获取名字的最后一个字符
$replaceStr = ''; // 初始化替换字符串
for ($i = 0;$i < $strlen - 2;$i++) {
$replaceStr .= '*'; // 根据需要替换的字符数量,生成相应数量的星号
}
return $firstStr .$replaceStr . $lastStr; // 返回替换后的名字
}
}