PHP 匿名处理处理用户昵称

    /**
     * 匿名处理处理用户昵称
     * @param $name
     * @return string
     */
    function conduct_name($name,$type = 1)
    {
    
    
        if($type == 1){
    
    
            return mb_substr($name, 0, 1, 'UTF-8') . '**' . mb_substr($name, -1, 1, 'UTF-8');
        }else{
    
    
            $strLen = mb_strlen($name, 'UTF-8');
            $min = 3;
            if ($strLen <= 1)
                return '*';
            if ($strLen <= $min)
                return mb_substr($name, 0, 1, 'UTF-8') . str_repeat('*', $min - 1);
            else
                return mb_substr($name, 0, 1, 'UTF-8') . str_repeat('*', $strLen - 1) . mb_substr($name, -1, 1, 'UTF-8');
        }
    }

猜你喜欢

转载自blog.csdn.net/weixin_40854327/article/details/112840144
今日推荐