标签:code 问题 substr sts i++ use sub || UNC
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;
}
/*
普通截取
*/
function hide_name($name, $sep = ‘*‘)
{
$len = strlen($name);
$str = ‘‘;
for ($i = 0; $i < $len; $i++) {
$str .= ($i == 0 || $i == $len - 1) ? $name{$i} : $sep;
}
return $str;
}
标签:code 问题 substr sts i++ use sub || UNC
原文地址:https://www.cnblogs.com/qixidi/p/10206084.html