1. 程式人生 > 其它 >PHP 匿名處理處理使用者暱稱

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'); } }