From 3387dae2b397c7318e35353c3283f60e64bc002c Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Thu, 18 Jul 2024 18:30:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(statistics):=20=E4=BF=AE=E6=94=B9IndexCont?= =?UTF-8?q?roller=E4=BB=A5=E9=9A=90=E8=97=8F=E7=94=A8=E6=88=B7=E6=98=B5?= =?UTF-8?q?=E7=A7=B0=E4=B8=AD=E9=97=B4=E9=83=A8=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/statistics/controller/IndexController.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/statistics/controller/IndexController.php b/app/statistics/controller/IndexController.php index 5e7678f64..ecded2100 100644 --- a/app/statistics/controller/IndexController.php +++ b/app/statistics/controller/IndexController.php @@ -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; // 返回替换后的名字 + } }