【PHP】中文姓名->改为星号

依然范儿特西
2019-02-15 / 0 评论 / 1,320 阅读 / 正在检测是否收录...
<?php

header("Content-type: text/html; charset=utf-8"); 
$str = "老李";
echo substr_cut($str);
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');
    return $strlen == 2 ? $firstStr . str_repeat('*', mb_strlen($user_name, 'utf-8') - 1) : $firstStr . str_repeat("*", $strlen - 2) . $lastStr;
}
0

评论 (0)

取消