/* * 提取数字并去数据库取得相应的分类名 * $strs 需要处理的字符串 * $table 数据表名 * $condition 条件字段 * $field 获取的字段 */ public function extractNumberGetName($strs,$table,$condition,$field){ if(empty($strs)){ return ''; } $patterns = "/\d+/"; preg_match_all($patterns,$strs,$arr); if(empty($arr[0])){ return ''; } $map[$condition] = array ('in',$arr[0]); $model = D($table); $result = $model->field($field)->where($map)->select(); $str = ''; $i = 0; foreach ($result as $key => $item) { if($i == 0 ){ $str .= $item[$field]; }else{ $str .= ','.$item[$field]; } $i++; } return $str; }