Home >Backend Development >PHP Tutorial > foreach结合samrty 数据如何不显示呢
foreach结合samrty 数据怎么不显示呢
$load_list是一个二维数组,其中的$v['user_name']有以下数据
xiaodg,
x42466,
etea,
na0617,
kimo,
留影,
vian22,
qingyu,
jiangliman,
xiaobu,
xiaobu,
hfa818,实现的结果将两个字符后面的用*代替,下面是实现*代码,
foreach($load_list as $k=>&$v){
//print_r($v);
//exit;
$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
if($k>2) {
$t .= '*';
}else {
$t .= mb_substr($temp, $k, 1);
}
}
$t=&$v['user_name'];
}
这是assign赋值:
$GLOBALS['tmpl']->assign("load_list",$load_list);
然后在页面用samrty显示:
{foreach from="$load_list" item="load"}