Home >Backend Development >PHP Problem >How to hide username in php
php method to hide username: first open the corresponding PHP file; then create a "substr_cut" method; then use the if statement to retain only the first and last characters of the string and hide the intermediate information.
Recommended: "PHP Video Tutorial"
php Hide Username
/** * 只保留字符串首尾字符,隐藏中间用*代替(两个字符时只显示第一个) * @param string $user_name 姓名 * @return string 格式化后的姓名 */ function substr_cut($user_name){ $strlen = mb_strlen($user_name, 'utf-8'); $firstStr = mb_substr($user_name, 0, 1, 'utf-8'); $lastStr = mb_substr($user_name, -1, 1, 'utf-8'); if($strlen<2) { return $user_name; } else { return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr; } }
The above is the detailed content of How to hide username in php. For more information, please follow other related articles on the PHP Chinese website!