时间:2021-07-01 10:21:17 帮助过:12人阅读
$temp = '判断是否有中文';判断*****
//判断是否有中文
if(preg_match('/[\x81-\xfe][\x40-\xfe]/',$temp)){
mb_internal_encoding("gbk");
}else {
mb_internal_encoding("utf-8");
}
$len = mb_strlen($temp);
$t = '';
for($k=0; $k<$len; $k++){
if($k>1) {
$t .= '*';
}else {
$t .= mb_substr($temp, $k, 1);
}
}
echo $t;
$load_list =array(
array('user_name' => 'xiaodg'),
array('user_name' => 'x42466'),
array('user_name' => 'etea'),
array('user_name' => 'na0617'),
array('user_name' => 'kimo'),
array('user_name' => '留影'),
array('user_name' => 'vian22'),
array('user_name' => 'qingyu'),
array('user_name' => 'jiangliman'),
array('user_name' => 'xiaobu'),
array('user_name' => 'xiaobu'),
array('user_name' => 'hfa818'),
);
foreach($load_list as $k=>&$v){
$temp=$v['user_name'];
//判断是否有中文
if(preg_match('/[\x81-\xfe][\x40-\xfe]/',$temp)){
mb_internal_encoding("gbk");
}else {
mb_internal_encoding("utf-8");
}
$len = mb_strlen($temp);
$t = '';
for($k=0; $k<$len; $k++){
if($k>2) {
$t .= '*';
}else {
$t .= mb_substr($temp, $k, 1);
}
}
$v['user_name'] = $t;
}
print_r($load_list);
Array
(
[0] => Array
(
[user_name] => xia***
)
[1] => Array
(
[user_name] => x42***
)
[2] => Array
(
[user_name] => ete*
)
[3] => Array
(
[user_name] => na0***
)
[4] => Array
(
[user_name] => kim*
)
[5] => Array
(
[user_name] => 留影
)
[6] => Array
(
[user_name] => via***
)
[7] => Array
(
[user_name] => qin***
)
[8] => Array