//订单详情 public function details(){ $id = I('get.id'); $comm = $this->getInstance(); $res = $comm->select_view(1,0,'orders'); $res = $res['list'][0]; $needRep = array( 'username','address','mobile','expressno' ); foreach($res as $key => $row){ if(in_array($key,$needRep)){ if($row){ $need = $this->repStar($row,"utf-8"); $res[$key] = $need; } } } $this->assign('data',$res); $this->display(); } //换星星 private function repStar($str,$encoding = "utf-8"){ $len = mb_strlen($str,$encoding); //判断是否大于2 $need = null; if(!$len){ return false; } if($len>1){ if($len%2 !=0){ $len -= 1; } $need = mb_substr($str,0,$len/2,$encoding); $star = $this->getStar($len/2+1); $need .= $star; }else{ $need = "*"; } return $need; } //生成需要的星星 private function getStar($nun){ $reVal = null; if($nun){ for($i = 0; $i < $nun; $i++){ $reVal .= "*"; } return $reVal; }else{ return false; } }