Home  >  Article  >  Backend Development  >  How to hide username in php

How to hide username in php

藏色散人
藏色散人Original
2020-08-27 10:44:082620browse

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.

How to hide username in php

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(&#39;*&#39;, mb_strlen($user_name, &#39;utf-8&#39;) - 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn