PHP只显示姓名首尾字符,隐藏中间字符并用*替换
PHP只显示姓名首尾字符,隐藏中间字符并用*替换代码如下:<?php
$xm = "我是中文";
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;
}
echo substr_cut($xm);
?>
页:
[1]