姓名掩码处理

$user_name= ‘张三’;

$strlen= mb_strlen($user_name,'utf-8');

if($strlen>=2){

$firstStr= mb_substr($user_name,0,1,'utf-8');

$lastStr= mb_substr($user_name,-1,1,'utf-8');

$user_name=$strlen==2?$firstStr. str_repeat('*',mb_strlen($user_name,'utf-8') -1) :$firstStr. str_repeat("*",$strlen-2) .$lastStr;

}

你可能感兴趣的:(姓名掩码处理)