feat : mypage

This commit is contained in:
2025-03-28 09:52:06 +08:00
parent 02b51081d3
commit 2feb14361e
3 changed files with 101 additions and 0 deletions

View File

@@ -96,4 +96,25 @@ class StringUtil
mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff)
);
}
/**
* @param $str
* @param int $num
* @return string
*/
public static function maskMiddleStrByNum($str,int $num) {
$len = strlen($str);
if ($len <= $num) {
return str_repeat('*', $num);
}
$left_len = floor(($len - $num) / 2);
$right_len = ($len - $num) - $left_len;
$left = substr($str, 0, $left_len);
$right = substr($str, -$right_len);
return $left . '****' . $right;
}
}