search
HomeBackend DevelopmentPHP ProblemHow to hide username in php

How to hide username in php

Aug 27, 2020 am 10:44 AM
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.

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.