php hide the user name

/**
 Leaving only the first and last characters string *, * hiding place with intermediate (only when the first two characters)
 * @Param string $ user_name Name
 * After @return string formatted name
 */
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;
    }
}

Guess you like

Origin www.cnblogs.com/ssx314/p/11563939.html